CONTROLLING A MOVIE ON A LEVEL


You can control a movie loaded into a level from another timeline or from within itself. You'll remember from Lesson 3 that the target path to a movie loaded into a level is simply its level number. For example, if you've loaded a movie into Level 5, you would use the following syntax to make it rotate from any other timeline currently in the player window:

 _level5._rotation = 45; 

Pretty straightforward and simple.

It's also easy to place an action on Frame 1 of a loaded movie so that it does something immediately upon loading. We'll look at both approaches in the following exercise, in which we'll script our banner movies to reposition themselves correctly upon loading as well as create a banner On/Off button.

  1. Open virtualaquarium5.fla in the Lesson17/Assets folder.

    This is the file we worked on in the previous exercise. Take note of the white rectangle on the stage: This is a movie clip instance named bannerBack. The location of this instance's registration point (top left of the instance) will be pivotal in a script that repositions the banner movies when they're loaded into Level 1. Because this repositioning script will reside within the banner movies, we need to open the banner movie authoring files.

    graphics/17fig16.gif

  2. Choose File > Open. Navigate to the Lesson17/Assets folder, locate the file named banner0.fla, and open it in Flash.

    This simple animated movie is made up of five layers, the top of which is named Actions. We'll place a two-line script on Frame 1 so that as soon as the banner movie is loaded, the script is executed.

  3. With the Actions panel open, select Frame 1 of the Actions layer and add the following script:

     _x = _level0.bannerBack._x;  _y = _level0.bannerBack._y; 

    These two lines of script set the x and y properties of this movie to match the x and y properties of the bannerBack movie clip instance on Level 0. This will cause the banner movie to load exactly on top of the bannerBack instance, even if it's eventually moved from its current location.

  4. Add this same script to Frame 1 of the other banner movies (banner1.fla and banner2.fla). Then re-export them as banner0.swf, banner1.swf, and banner2.swf, respectively.

  5. Return to virtualaquarium5.fla. Choose Control > Test Movie.

    Once again, a random banner is loaded. However, this time it loads at the proper location. If you wait ten seconds, a different banner may load, also at the proper location in relation to bannerBack.

    graphics/17fig17.gif

    Since you can't attach an onClipEvent() to a movie loaded into a level, this is the best approach for triggering an action to occur as soon as the movie loads.

  6. Close the test movie to return to the authoring file (virtualaquarium5.fla).

    The banner movie loaded into Level 1 can easily be controlled from this movie as well. We will next script a button to demonstrate this.

  7. With the Actions panel open, select the button with the text 'Banner On/Off' and add the following script:

     on(release) {  _level1._visible = !_level1._visible;  bannerBack._visible = !bannerBack._visible;  } 

    This script creates a toggling functionality that makes both the banner movie loaded into Level 1 and the bannerBack movie clip instance either visible or invisible, depending on its current state. This syntax (use of the NOT (! ) operator) provides a quick and easy way to reverse Boolean values of any kind.

  8. Choose Control > Test Movie.

    Press the On/Off button several times to test its functionality. Wait 10 seconds for the banner to change. The button will continue to work because it's set up to control the movie loaded into Level 1 rather than a particular banner movie.

  9. Close the test movie. Save the file as virtualaquarium6.fla.

    This completes the exercise. We'll continue to build on this file in the following exercises.

NOTE

Security issues can arise when loading files from different domains into a single Player window. There are a few restrictions to be aware of. For example, if a movie at www.derekfranklin.com/derekMovie.swf is being played, and it contains an action to load a movie located at www.electrotank.com/jobeMovie.swf into Level 5, these two movies initially will not be able to exchange data via ActionScript, since they were loaded from different domains. A permission setting for allowing movies loaded from different domain's to access each other's data can be used to override this restriction. In this scenario, if derekMovie.swf contains the setting (placed on Frame1): System.security.allowDomain(" www.electrotank.com "), then jobeMovie.swf (loaded from electrotank.com) will have access to the data in derekMovie.swf. If jobeMovie.swf contains the setting: System.security.allowDomain(" www.derekfranklin.com ") then derekMovie.swf (loaded from derekfranklin.com) will have access to the data in jobeMovie.swf . This restriction does not exist for movies loaded from the same domain.


Thus far, we've concentrated on loading and controlling graphical content. However, any good Flash developer knows that graphics are just a part of any great multimedia project. You also need sound. However, sound contributes significantly to file size, which means smart sound management is key. In the next two exercises, we'll show you how to use audio in your projects to your heart's content (well, almost)!



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