TARGETING THE MAIN MOVIE


The main, or root, movie represents the main timeline of a SWF. All of your project's other timelines exist, in some way, inside this one.

graphics/03fig08.gif

Targeting the main timeline is very simple. The syntax would be as follows:

 _root.play(); 

You can place this script on any timeline exactly as shown and it will always cause the main timeline to play.

NOTE

A movie loaded into a level is also considered a root timeline. We'll explain how this affects your scripting in the section " Targeting Movies on Levels.'"


  • 1) Open rootTarget1.fla in the Lesson03/Assets folder.

    This file is similar to the one we just finished working on except that two buttons appear in the lower-right portion of the stage. We will script these to resize the main timeline when clicked. We will then copy these buttons, place them inside of our movie clip instances, and without modifying the target paths used in the script demonstrate how you can use _root to target the main timeline from any other timeline in the SWF.

  • 2) With the Actions panel open, select the button with the minus sign over it and add the following script:

     on (release) {    _root._xscale = _root._xscale - 10;    _root._yscale = _root._yscale - 10;  } 

    When this button is pressed and released, the main timeline's size will be reduced by 10 percent. One thing to note: Since the button to which we're attaching this action resides on the main timeline which is also the timeline affected by the button this script doesn't really require a target path. We simply use an absolute target path here to demonstrate their universal effectiveness.

  • 3) With the Actions panel open, select the button with the plus sign over it and add this script:

     on (release) {    _root._xscale = _root._xscale + 10;    _root._yscale = _root._yscale + 10;  } 

    This script is similar to the last one except that this time when this button is pressed and released, the main timeline's size will increase by 10 percent.

  • 4) Drag-select both buttons (as well as the text on top of the buttons) and copy them. Double-click one of the movie clip instances on the stage to edit it in place. Paste the buttons on the 'Change root buttons' layer on the movie clip's timeline and position them just below and center of the current graphics.

    Although these copies of the buttons on the main timeline exist within this movie clip timeline, the actions attached to them still target the main timeline because a _root target path always refers to the main timeline of the movie (SWF).

  • 5) Choose Control > Test movie to test the project.

    The first thing you'll notice is that every instance of our movie clip includes the buttons. In addition, the buttons appear in their original placement on the bottom-right portion of the stage. Click any of these buttons, and you get the same result: The main timeline is resized. As it resizes, however, something interesting occurs: All of the other timelines are resized as well. This is due to the parent-child relationship between the main timeline and the movie clip instances on it something we'll discuss in more detail in the next exercise.

  • 6) Close the testing environment to return to the authoring environment. Save the project as rootTarget2.fla.

    We will build on this file (with a few modifications) in the following exercise.



Macromedia Flash MX ActionScripting Advanced. Training from the Source
Macromedia Flash MX ActionScripting: Advanced Training from the Source
ISBN: 0201770229
EAN: 2147483647
Year: 2002
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net