Groups | Blog | Home
all groups > flash actionscript > august 2005 >

flash actionscript : About the "_root" function and loading external swfs


PixelFool
8/21/2005 10:40:44 PM
Hello everyone,
I'm trying to figure out what "_root" points to in this context:
I have a main movie. In this movie, I have a blank mc that loads in an
external swf.
In this external swf, I have actionscript, some lines of which point to
"_root.blahblah.dothis".
In this case, does _"root" point to the main stage of the external swf, or the
movie in which it is loaded?

How would I target the file something is in, rather than in what it is loaded?
Thanks a ton guys!!
PixelFool
QuivalenSoth
8/21/2005 11:55:33 PM
Hi there,

Try not to think of loading external movies as a seperate entity, (like you
would an include file). When you load a movie clip in, it becomes a part of the
tree structure of your original clip. Remember, when you load a Clip in, you're
loading it in either by target or by level. So try to think of it like a
building a tree structure and the top of your tree will always be your root.

As for using lockroot. The point of lockroot is when you're dealing with an
external SWF file that doesn't know about its parent, so it thinks the root
exists in its own file.

PK
Jeckyl
8/22/2005 12:00:00 AM
_root always means the root (top level timeline) of the movie that is
playing (in a given level). SO when you load a SWF into a clip, the _root
does NOT refer to the top level timeline of the movie you loaded in, because
now that movie is nested in a clip, and what was its _root before you loaded
it is no longer the top level timeline.

You can use lockroot to force the _root to be at a particular clip (for all
its children) instead of the top level. That means the _root can be
different things to different clips (which can be confusing). I'm not sure
how Flash actually decides which _root is required .. and because one can
think of simple situations where it is would be confusing, I would not trust
lockroot too far. eg not sure what would happen if you had this code in a
loaded SWF....

_global.f = function() { return _root; }

would you then call f() from the main movie (not the loaded SWF), would it
return the root of the main movie, or the root of the loaded swf? Which one
SHOULD it return? What if you've used lockroot and you WANT to refer to the
root of the main movie in some cases. Its just too tricky and confusing.

Instead, just avoid use _root in your movies .. use relative addressing
(using _parent, _parent._parent etc) wherever possible, or pass a reference
to a clip to the other clips and functions that need to refer to it.
--
Jeckyl

AddThis Social Bookmark Button