TARGETING MOVIES ON LEVELS


Using the loadMovie() action, Flash enables you to load more than one .swf file into the Flash player window simultaneously (something you'll learn how to do in the exercise that follows and that we discuss more in depth in Lesson 17, Loading External Content). SWFs exist in the player window in what are known as levels. Functionally, levels (for holding SWFs) are similar to layers (for holding content) on a timeline: They are a plane of existence, a depth, that puts a loaded SWF and all its content on top of or below other movies that have been loaded in the player window. You can load hundreds of external .swf files into various levels in the player window.

When you use the loadMovie() action to load a movie into a level, you must assign a level number to load the movie into. However, you don't need to load movies into sequential levels; you can assign arbitrary numbers, such as 46 or 731, if you'd rather. Once a movie has been loaded into a level, its target path to timelines on other levels is its level number. For example, if you were to load a movie into Level 37, movies on other levels would target that movie using the following target path:

 _level37 

To tell the main timeline on this level to stop, you would use the following syntax:

 _level37.stop (); 

NOTE

The first movie to appear in the player window automatically loads into Level 0.

A level's target path is the key to controlling the SWF loaded there, including its main timeline and any movie clip instances it may contain.

Because you're loading multiple SWFs into the player window using the loadMovie() action, its important to note that each SWF's main timeline is considered the _root timeline in relation to other movies within that SWF. Thus, although a SWF loaded into a level might be addressed as _level37 by movies on other levels, the main timeline of that SWF can be addressed as _root by movie clip instances within that same SWF. This means that if movies have been loaded into 15 levels, there are a total of 16 root movies (including the one on Level 0). Whenever a timeline targets another timeline on that same level, it can use a relative target path.


graphics/03fig14.gif

In the following exercise, we'll load movies into Levels 1 and 2, then control them from Level 0.

  1. Open backgroundControl1.fla in the Lesson03/Assets folder.

    This is the movie that will be loaded into Level 1. It looks like an operating system dialog box, and it contains a single scene made up of six layers, each of which is named according to its content.

    In the next exercise we'll script the functionality of many of the buttons you see. For now, we'll simply make the window draggable as well as allow it to be closed.

  2. With the Actions panel open, select Frame 1 on the main timeline and add the following script:

     _visible = false; 

    Since this action targets the current movie, and this movie will be loaded into Level 1, the movie on Level 1 will be invisible when it's first loaded giving the effect of a closed window when it is initially loaded. A script on Level 0 will be used to "open" it, or make it visible.

  3. With the Actions panel open, select the round Exit button (with an X on it) and add the following script:

     on (release) {    _visible = false;  } 

    This button will be used to "close" the window if it has been made visible.

  4. With the Actions panel open, select the rectangular invisible button at the top of the dialog box and add the following script:

     on (press) {    _alpha = 50;    startDrag (this);  }  on (release) {    _alpha = 100;    stopDrag ();  } 

    graphics/03fig15.gif

    When this button is pressed, this movie will become 50 percent transparent as well as draggable. When the button is released, the movie will once again become 100 percent opaque and dragging will stop thus emulating the effect of a draggable dialog box.

    It's important to note that since we know this movie will be loaded into Level 1, the following syntax would work as well.

     on (press) {    _level1._alpha = 50;    startDrag ();  }  on (release) {    _level1._alpha = 100;    stopDrag ();  } 

    Notice how the action that changes the movie's transparency now contains an absolute target path to Level 1. Although this will work, there's a major disadvantage to using absolute target paths to script actions that affect a movie's own timeline. Using the above example, we know this movie will be loaded into Level 1, so we can use an absolute target path to Level 1 in our script. But if our project were a bit more dynamic, it might allow this movie to be loaded into any level arbitrarily (say Level 82). In this case, the line of script that changes the alpha property will not work, since it targets the movie on Level 1, but this movie is actually loaded into Level 82. By using a relative path in these scripts (as the first script shown in this step), you ensure that the movie can be loaded into any level and that all of its scripts will continue to work properly.

  5. Export this movie as backgroundControl.swf in the Lesson03/Assets folder.

    This creates a SWF from our project, which will be loaded into Level 1.

    Now let's set up the movie that will be loaded into Level 2.

  6. Save your work as backgroundControl2.fla.

    We'll work with this file again in the next exercise.

  7. Open textBox1.fla in the Lesson03/Assets folder.

    This movie will be loaded into Level 2. As with the last movie we worked on, this movie resembles an operating system dialog box. It contains a single scene made up of four layers, each of which is named according to its content.

    All of the scripts we're adding to this file are the same, and they work just like those we added to the previous file. The only difference is that they affect this movie, which is loaded into Level 2.

  8. With the Actions panel open, select Frame 1 on the main timeline and add the following script:

     _visible = false; 

    Since this action targets the movie that will be loaded into Level 2, the movie on Level 2 will be made invisible on loading with the same effect as described in Step 2.

  9. With the Actions panel open, select the round Exit button (with an X on it) and add the following script:

     on (release) {    _visible = false;  } 

    This button will be used to "close" the window if it has been made visible.

  10. With the Actions panel open, select the rectangular invisible button at the top of the dialog box and add the following script:

     on (press) {    _alpha = 50;    startDrag (this);  }  on (release) {    _alpha = 100;    stopDrag ();  } 

    When this button is pressed, the movie in Level 2 will become 50 percent transparent as well as draggable. When the button is released, that movie will once again become 100 percent opaque and dragging will cease with the same effect as that described in Step 4.

    You're finished scripting this movie for the time being.

  11. Export this movie as textBox.swf in the Lesson03/Assets folder.

    This creates a SWF from our project, which will be loaded into Level 2.

  12. Save your work as textBox2.fla.

    We'll work with this file again in the next exercise.

  13. Open levelTarget1.fla in the Lesson03/Assets folder.

    This is the movie that will be loaded into the player initially (into Level 0, though we don't need to define this). We will add actions to this movie to load backgroundControl.swf into Level 1 and textBox.swf into Level 2. We will then add actions that enable us to control these movies from Level 0.

    graphics/03fig16.gif

    This file takes the appearance of an operating system desktop. It contains a single scene made up of four layers, each named according to its content.

  14. With the Actions panel open, select Frame 1 and add the following script:

     loadMovieNum ("backgroundControl.swf", 1);  loadMovieNum ("textBox.swf", 2); 

    The first action loads backgroundControl.swf into Level 1, and the second action loads textBox.swf into Level 2.

    Remember that both of these movies are set up to become invisible on loading. To make them visible, we must script two of the buttons on our desktop which we'll do next.

  15. With the Actions panel open, select the button on the left of the stage that resembles a computer icon and add the following script:

     on (release) {    _level1._visible = true;  } 

    This action makes the movie loaded into Level 1 visible emulating the effect of a dialog box opening. As you can see, targeting a movie loaded into a level is very straightforward.

  16. With the Actions panel open, select the button on the left of the stage that resembles a paper scroll and add the following script:

     on (release) {    _level2._visible = true;  } 

    This has the same effect as the script on the last button, only this will make the movie loaded into Level 2 visible when pressed.

    Next, let's set up the buttons that will be used to scale the movies on Levels 1 and 2.

  17. With the Actions panel open, select the left-arrow button to the left of the 1, at the bottom of the screen, and add the following script:

     on (release) {    _level1._xscale = _level1._xscale - 5;    _level1._yscale = _level1._yscale - 5;  } 

    When this button is pressed then released, the horizontal and vertical proportions of the movie on Level 1 will be scaled down to their current values minus five.

  18. With the Actions panel open, select the right-arrow button to the left of the 1 at the bottom of the screen, and add the following script:

     on (release) {    _level1._xscale = _level1._xscale + 5;    _level1._yscale = _level1._yscale + 5;  } 

    These actions have the same effect as those discussed in the last step except that they increase the horizontal and vertical proportions of the movie on Level 1.

  19. With the Actions panel open, place the following actions, respectively, on the two buttons on either side of the 2 at the bottom of the screen:

    Place on left-pointing button:

     on (release) {    _level2._xscale = _level2._xscale - 5;    _level2._yscale = _level2._yscale - 5;  } 

    Place on right-pointing button:

     on (release) {    _level2._xscale = _level2._xscale + 5;    _level2._yscale = _level2._yscale + 5;  } 

    These actions have the same effect as those discussed in the last two steps except that they control the movie loaded into Level 2.

  20. Choose Control > Test Movie to test the project's functionality.

    When this project begins playing, backgroundControl.swf is loaded into Level 1 and textBox.swf is loaded into Level 2. However, you may remember that we set up these movies to be invisible on loading. Clicking either of the icon buttons on the desktop that we scripted will show the appropriate movie on that level. With the movies visible, press the scale buttons at the bottom of the screen to see how movies loaded into levels can be targeted. You can also drag these movies using the drag buttons we set up, or you can close one of these "dialog box" windows by pressing the Exit button on either.

  21. Close the testing environment to return to the authoring environment and save your work as levelTarget2.fla.

    We will use this file (with a small addition) in the next 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