AS3 trouble instantiating Document Class of loaded SWF
- by Marcy Sutton
I am loading one swf into another using the Loader class, but when the child swf finishes loading and is added to the display list, its Document Class is not instantiated. I have a few trace statements should execute when the object is created. When I compile the child SWF on its own, the Document Class runs as expected.
So I'm wondering... how do I associate a child SWF's Document Class with Loader.content?
// code in parent SWF's Document Class (Preloader)
public function Preloader(){
swfLoader = new Loader();
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderDone);
swfLoader.load(new URLRequest("mainmovie.swf"));
}
private function loaderDone(e:Event):void {
// Add Loader.content to new Sprite
mainMovie = Sprite(e.target.content);
mainMovie.alpha = 0;
swfLoader = null;
addChildAt(mainMovie, 0);
mainMovie.addEventListener(Event.ADDED_TO_STAGE, mainMovieAddedListener);
}
// functions in MainMovie.as not ever running,
// even though it is listed as the child SWF's Document Class
Cheers!