Tải bản đầy đủ (.pdf) (5 trang)

Tài liệu Controlling a Movie on a Level ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (17.93 KB, 5 trang )


< Day Day Up >

Controlling a Movie on a Level
You can control a movie loaded into a level from another timeline or from within the
movie itself. 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;


Straightforward and simple. It's also easy to place an action on Frame 1 of a loaded
movie so that it takes some action 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.
We'll continue working with this file from the preceding exercise. The white
rectangle on the stage is a movie clip instance named bannerBack_mc. The
location of this instance's registration point (upper-left corner 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's authoring files.

2. Choose File > Open. Navigate to the Lesson18/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:


4.
5. _x = _level0.bannerBack_mc._x;
6.
7. _y = _level0.bannerBack_mc._y;
8.

These two lines of script set the x and y properties of this movie to match the x
and y properties of the bannerBack_mc movie clip instance on Level 0. This
technique causes the banner movie to load exactly on top of the bannerBack_mc
instance, even if bannerBack_mc is eventually moved from its current location.
4. Add the script from Step 3 to Frame 1 of the other banner movies (banner1.fla and
banner2.fla); then re-export the three movies as banner0.swf, banner1.swf, and
banner2.swf, respectively.
5. Return to virtualaquarium5.fla. Choose Control > Test Movie.
Again, a random banner is loaded; however, this time it loads at the proper
location. If you wait 10 seconds, a different banner may load, also at the proper
location in relation to bannerBack_mc.

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'll script a button to demonstrate this principle.
7. With the Actions panel open, select Frame 1 of the Actions layer and add the
following script at the end of the current script:
8.
9. bannerControl_btn.onRelease = function() {
10.
11. _level1._visible = !_level1._visible;
12.

13. bannerBack_mc._visible = !bannerBack_mc._visible;
14.
15. }
16.

This script adds an onRelease event handler to the bannerControl_btn instance.
This step creates a toggling functionality that makes both the banner movie loaded
into Level 1 and the bannerBack_mc movie clip instance either visible or
invisible, depending on the current state of the instance when the instance is
clicked. Using the NOT (!) operator provides a quick and easy way to reverse
Boolean values of any kind.
8. Choose Control > Test Movie.
Click the On/Off button several times to test its functionality. Wait 10 seconds for
the banner to change. The button continues 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 step completes the exercise. We'll continue to build on this file in the
following exercises.
It's important to note that security issues can arise when loading files from
different domains into a single player window (the Flash player considers a
subdomain as a different domain). There are a few restrictions to keep in mind.
For example, if a movie at www.derekfranklin.com/derekMovie.swf is being
played and contains an action to load a movie located at
www.electrotank.com/jobeMovie.swf into Level 5, these two movies initially
won't be able to exchange data via ActionScript because they were loaded from
different domains. A permission setting for allowing movies loaded from different
domains to access each other's data can be used to override this restriction. In this
scenario, if derekMovie.swf contains the following setting (placed on Frame 1):

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 this setting:

System.security.allowDomain("www.derekfranklin.com")


then derekMovie.swf (loaded from derekfranklin.com
) will have access to the data
in jobeMovie.swf.
To this point in the lesson, we've concentrated on loading and controlling
graphical content; however, a good Flash developer knows that graphics are just
part of any great multimedia project. You also need sound, but sound contributes
significantly to file size, which means that smart sound management is key. In the
next two exercises, we'll show you how to use audio efficiently in your projects.

< Day Day Up >

×