views:

35

answers:

2

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 Loader) && DisplayObject(target).parent != null){
  target = DisplayObject(target).parent;
}

Thanks.

A: 

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.

Amarghosh
+1  A: 

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;
geo