Specifying a root timeline for loaded SWF files
The
ActionScript property specifies or contains a reference to the root timeline of a
_root
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
returned. However, the timeline that
SWF file is running independently (in its own level) or was loaded into a movie clip instance
by a
call.
loadMovie()
In the following example, consider a file named container.swf that has a movie clip instance
named
on its main timeline. The container.swf file declares a variable named
target_mc
on its main timeline; the same script then loads another file called contents.swf into
userName
the
movie clip:
target_mc
// In container.swf:
_root.userName = "Tim";
target_mc.loadMovie("contents.swf");
my_btn.onRelease = function():Void {
trace(_root.userName);
};
In the following example, the loaded SWF file, contents.swf, also declares a variable named
on its root timeline:
userName
// In contents.swf:
_root.userName = "Mary";
After contents.swf loads into the movie clip in container.swf, the value of
attached to the root timeline of the hosting SWF file (container.swf ) would be set to
instead of
. This could cause code in container.swf (as well as contents.swf ) to
"Tim"
malfunction.
To force
to always evaluate to the timeline of the loaded SWF file, rather than the
_root
actual root timeline, use the
loading the SWF file or by the SWF file being loaded. When
movie clip instance, that movie clip acts as
is set to
_lockroot
true
other SWF file loads it. Any movie clip, and any number of movie clips, can set
. By default, this property is
true
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;
356
Working with Movie Clips
specifies can change, depending on whether a
_root
property. You can set this property either by the
_lockroot
_root
within a SWF file, that SWF file acts as its own root, no matter what
.
false
_root
_lockroot
for any SWF file loaded into it. When
,
is
_level1
that's
userName
"Mary"
is set to
on a
true
to
_lockroot
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?