490
ActionScript classes
If you don't have access to Chess.fla (for example, if you are loading Chess.swf from someone
else's site into
chess_mc
), you can set the Chess.swf
_lockroot
property when you load it.
Place the following ActionScript on the main Timeline of Games.fla:
chess_mc._lockroot = true;
In this case, Chess.swf can be published for any version of Flash Player, as long as Games.swf
is published for Flash Player 7 or later.
When calling
loadMovie()
, set the
MovieClip._lockroot
property to
true
in the loader
movie, as shown in the following code. If you don't set
_lockroot
to
true
in the loader
movie, any references to
_root
in the loaded movie point to the
_root
of the loader instead of
the
_root
of the loaded movie:
myMovieClip._lockroot = true;
Availability:
ActionScript 1.0; Flash Lite 2.0
Example
In the following example, lockroot.fla has
_lockroot
applied to the main SWF file. If the
SWF file is loaded into another FLA document,
_root
always refers to the scope of
lockroot.swf, which helps prevent conflicts. Place the following ActionScript on the main
Timeline of lockroot.fla:
this._lockroot = true;
_root.myVar = 1;
_root.myOtherVar = 2;
trace("from lockroot.swf");
for (i in _root) {
trace(" "+i+" -> "+_root[i]);
}
trace("");
which traces the following information:
from lockroot.swf
myOtherVar -> 2
myVar -> 1
_lockroot -> true
$version -> WIN 7,0,19,0
The following example loads two SWF files, lockroot.swf and nolockroot.swf. The
lockroot.fla document contains the ActionScript from the preceding example. The nolockroot
FLA file has the following code placed on Frame 1 of the Timeline:
_root.myVar = 1;
_root.myOtherVar = 2;
trace("from nolockroot.swf");
for (i in _root) {
trace(" "+i+" -> "+_root[i]);
}
trace("");
Содержание Flash Lite 2
Страница 1: ...Flash Lite 2 x ActionScript Language Reference...
Страница 22: ...22 Contents...
Страница 244: ...244 ActionScript language elements...
Страница 760: ...760 ActionScript classes...