User Guide

208 Chapter 8: Working with Movie Clips
Develop a branching interface with links that lets the user select among several SWF files that
are used to display a site’s content.
Build a navigation interface with navigation controls in level 0 that loads content into other
levels. Loading content into levels helps produce smoother transitions between pages of
content than loading new HTML pages in a browser.
For more information on loading movies, see “Loading external SWF and JPEG files
on page 296.
Specifying a root Timeline for loaded SWF files
The _root ActionScript property specifies or contains 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.
In the following 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");
myButton.onRelease = function() {
trace(_root.userName);
};
In the following example, the loaded SWF file, contents.swf, also declares a variable named
userName on its root Timeline:
// In contents.swf:
_root.userName = "Mary";
After contents.swf loads into the movie clip in container.swf, the value of userName that’s
attached to the root Timeline of the hosting SWF file (container.swf ) would be set to
"Mary"
instead of "Tim". This could cause code in container.swf (as well as contents.swf) to malfunction.
To f or c e
_root to always evaluate to the Timeline of the loaded SWF file, rather than the actual
root Timeline, use the
_lockroot property. This property can be set either by the loading SWF
file or the SWF file being loaded. When
_lockroot is set to true on a movie clip instance, that
movie clip will act as
_root for any SWF file loaded into it. When _lockroot is set to true
within a SWF file, that SWF file will act as its own root, no matter what other SWF file loads it.
Any movie clip, and any number of movie clips, can set
_lockroot to true. By default, this
property is
false.
For example, the author of container.swf could put the following code on Frame 1 of the main
Timeline:
// Added to Frame 1 in container.swf:
target_mc._lockroot = true;