views:

36

answers:

1

I am developing a project in Flash Builder which will load a file built by Flash CS4. The code in Flash CS4 is below, it's a doc class. I am sure the dispatchEvent has been invoked:

package {
import flash.display.MovieClip;
import flash.events.Event;

public class flashcs extends MovieClip
{
    public function flashcs():void
    {
        dispatchEvent(new Event("onPlayerLoaded", true));
    }

    public function playVideo():void
    {
        return;
    }
}

}

In Flash Builder, I use below code to listen to the event, but the callback never get called:

            private function playerLoaded():void 
        {
            Player = MovieClip(Loader.content)
            Player.addEventListener("onPlayerLoaded",Callback);
        }
mx:SWFLoader id="Loader" source="http://localhost/flashcs.swf" init="playerLoaded()"

I think maybe I can only listen to a SystemManager but not on the MovieClip? Because I have one prior project, the loaded swf file is built by Flash Builder, I was listening to the SystemManager without any trouble.

Thanks.

A: 

Try within the complete event not the init, if the dispatchEvent have been fired before you have been able to listen to it you will not get it.

<mx:SWFLoader id="Loader" source="http://localhost/flashcs.swf" complete="playerLoaded()"/>

Edit:

In your loaded class delay the dispatch event to fired it when object is added to the stage:

package {
 import flash.display.MovieClip;
 import flash.events.Event;

 public class flashcs extends MovieClip
 {
    public function flashcs():void
    {
        addEventListener(Event.ADDED_TO_STAGE, ready);
    }

    private function ready():void {
     removeEventListener(Event.ADDED_TO_STAGE, ready); 

     dispatchEvent(new Event("onPlayerLoaded", true));
    }

    public function playVideo():void
    {
        return;
    }
 }
}
Patrick
Tried, but no luck...
Bin Chen
Ok i have made an edit, but i dont understand why you need a onPlayerLoaded event since you already know that it is loaded on listening to the complete/init event from the SWFLoader.
Patrick
Thanks, but it still can't work. The reason that I use that is that is the requirement from the upper layer.
Bin Chen
Strange in my test it works if i delay the dispatch event
Patrick
Hi, Patrick, can you send your test projects to me? I really appreciate that.
Bin Chen
Hi Patrick, I solve it by adding a timer of 2 seconds, in the timer handler I send the event so the container swf can receive... that is very weird, i am wondering is there any rule that i can use to ensure the container swf can receive my event?
Bin Chen