PDA

View Full Version : Loader.load SWF without "playing" before addChild?



HunterSkookum
October 30th, 2007, 12:19 PM
The setup:

parentClass.as/parentClass.fla <-- document root, has several Loaders which load external SWFs:

externalClass.as/externalClass.fla <-- one of the external documents

In externalClass several things reference the stage. In the *constructor* function I have added a trace which outputs "externalClass has been initialized." When I addChild the Loader.content, I trace "addChild: externalClass" ... when I run the parentClass, this is what gets traced:

1. "externalClass hass been initialized"
2. "Loader: Event.COMPLETE callback handler"
3. "addChild: externalClass"

This causes problems because the constructor of externalClass references the stage, which doesn't "exist" until the externalClass has been addChild'ed. Is there a way to load an external SWF in the background and "run" it later?

Thanks, I've been pounding my head on this for a while.

Hunter

senocular
October 30th, 2007, 12:35 PM
concerning what seems to be your problem, you should first check for stage and if not present use the ADDED_TO_STAGE event to run your stage specific code. It will be called when the swf/display object is actually added to the stage and the stage is accessible.

As for your question, you can load in a SWF into the player without it actually running using URLLoader to load in the SWF as binary data (urlLoader.dataFormat = URLLoaderDataFormat.BINARY). Then, when ready, add it to a Loader instance using loadBytes(). I am not sure, but my guess would be that even if you have the loader itself added as a child to the active display list, the stage of that loaded SWF may still not be accessible when using loadBytes. You can give it a whirl though ;)

HunterSkookum
October 30th, 2007, 02:34 PM
That's just what I needed. I won't be able to use that technique on this project (working with a compiled component which references the stage as soon as its instantiated) but I'll certainly be using that a lot.

Thanks!


concerning what seems to be your problem, you should first check for stage and if not present use the ADDED_TO_STAGE event to run your stage specific code. It will be called when the swf/display object is actually added to the stage and the stage is accessible.

As for your question, you can load in a SWF into the player without it actually running using URLLoader to load in the SWF as binary data (urlLoader.dataFormat = URLLoaderDataFormat.BINARY). Then, when ready, add it to a Loader instance using loadBytes(). I am not sure, but my guess would be that even if you have the loader itself added as a child to the active display list, the stage of that loaded SWF may still not be accessible when using loadBytes. You can give it a whirl though ;)