Search code examples
flashactionscript-3mxmlc

Load swf without instantiating


Is there a way I can load a swf file but not automatically instantiate it's DocumentClass?

Instead I want to do something like the following:

protected function mainLoaded(e:Event = null):void {
  trace('mainLoaded');
  var main:* = this.mainLoad.createClassByName('Main');
  trace(main);
}

where mainLoad is an instance of CasaLib's SwfLoad and createClassByName is the equivalent to loaderInfo.applicationDomain.getDefinition();

The thing is that when my swf finishes loading I can see it is created, because of some trace calls, although its obviously not added to the display list.


Solution

  • In your child swf's document class, use the following:

    //constructor
    public function ChildSWF()
    {
        if(stage) init()
        else addEventListener(Event.ADDED_TO_STAGE, init);
    
    }// end if
    
    private function init(e:Event = null):void
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        trace("This will only trace when an instance of ChildSWF is added to the stage, not when it's instantiated");
    
    }// end function