Specifying a root Timeline for loaded SWF files 123
The above code is also equivalent to the following:
with (donut){
hole._alpha = 20;
hole._xscale = 150;
hole._yscale = 150;
}
Loading and unloading additional SWF files
To play additional SWF files without closing Flash Player, or to switch SWF files without loading
another HTML page, you can use the global
loadMovie() function or loadMovie() method of
the MovieClip class. You can also use
loadMovie() to send variables to a CGI script, which
generates a SWF file as its CGI output. When you load a SWF file, you can specify a level or
movie clip target into which the SWF file will load. If you load a SWF file into a target, the
loaded SWF file inherits the properties of the targeted movie clip. Once the movie is loaded, you
can change those properties.
The
unloadMovie() method removes a SWF file previously loaded by loadMovie(). Explicitly
unloading SWF files with
unloadMovie() ensures a smooth transition between SWF files and
may decrease the memory required by Flash Player.
Use
loadMovie() to do any of the following:
• Play a sequence of banner ads that are SWF files by placing a loadMovie() function at the end
of each SWF file to load the next SWF file.
• Develop a branching interface that lets the user choose among several different SWF files.
• Build a navigation interface with navigation controls in level 0 that load other levels. Loading
levels produces smoother transitions than loading new HTML pages in a browser.
For more information on loading movies, see “Loading external SWF and JPEG files”
on page 194.
Specifying a root Timeline for loaded SWF files
The _root ActionScript property specifies or returns a reference to the root Timeline of a SWF
file. If a SWF file has multiple levels, the root Timeline is on the level that contains the currently
executing script. For example, if a script in level 1 evaluates
_root, _level1 is returned.
However, the Timeline specified by
_root can change depending on whether a SWF file is
running independently (in its own level) or has been loaded into a movie clip instance by a
loadMovie() call.
For example, consider a file named container.swf that has a movie clip instance named
target_mc
on its main Timeline. The container.swf file declares a variable named
userName on its main
Timeline; the same script then loads another file called contents.swf into the movie clip
target_mc.
// In container.swf:
_root.userName = "Tim";
target_mc.loadMovie("contents.swf");
The loaded SWF file, contents.swf, also declares a variable named userName on its root Timeline.
// In content.swf:
_root.userName = "Mary";