Question

I got problem when I am loading external swf which contains added_to_stage method. It execute two times. I don t understand why it is doing ? I am also interesting if both swfs have their own stage ?

Thank you for any answer

I am using greensock library to hanle loading.

Flash preloader:

package  {
    import flash.display.MovieClip;
    import com.greensock.loading.SWFLoader;

    public class Preloader extends MovieClip 
    {

        public function Preloader() 
        {
            var loader : SWFLoader = new SWFLoader("Prototype1.swf");
            loader.load();
            addChild(loader.content);
        }
    }
}

External SWF:

public class Prototype1 extends MySprite 
{

    public function Prototype1() 
    {   
        addEventListener(Event.ADDED_TO_STAGE, onAdded);    
    }

    private function onAdded(e:Event):void
    {
        trace("onAdded");
    }
}

OUTPUT: onAdded onAdded

Was it helpful?

Solution

The greensock documentation says:

suppressInitReparentEvents: Boolean - If true, the SWFLoader will suppress the REMOVED_FROM_STAGE and ADDED_TO_STAGE events that are normally dispatched when the subloaded swf is reparented into the ContentDisplay (this always happens in Flash when any DisplayObject that's in the display list gets reparented - SWFLoader just circumvents it by default initially to avoid common problems that could arise if the child swf is coded a certain way).

So you can change your code in Preloader.as to:

var loader:SWFLoader = new SWFLoader("Prototype1.swf", {suppressInitReparentEvents: true});

And you'll only get one call to onAdded.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top