I am using the Loader to load an external swf into my program. Inside the external swf, I need to be able to access the Loader instance that just loaded it.
Does the loader add the external swf to itself before any code inside the swf gets executed?
When is it safe to access the loader via the following code?
var target:DisplayObject = this;
while(!(target is L开发者_如何学Pythonoader) && DisplayObject(target).parent != null){
target = DisplayObject(target).parent;
}
Thanks.
The swf is loaded and added as a child before any code is executed.
You can reference the loader object through the LoaderInfo property of any DisplayObject in the loaded swf. So for your example:
var target:DisplayObject = this;
var loader:Loader = target.loaderInfo.loader;
I don't have a compiler handy, but you can try from the constructor of the document class - if it fails, try from Event.ADDED
or Event.ADDED_TO_STAGE
event handlers of this
object.
精彩评论