开发者

Unable to listen for an event dispatched from an embedded swf

I have an as3 class with an embedded swf. I need the embedded swf to dispatch an event and have the as3 class action on that event. This used to work fine when the embedded swf was embedded and had been loaded as an external swf, however now that it's embedded the listener never picks up on the dispatched event.

I've created a simplified example below, the 'onMovieComplete' function is never called.

/*  I have an external swf file 'movie.swf' with a simple animation in it.
 *  When the animat开发者_如何学JAVAion hits a frame (frame 70 in this case) it fires a
 *  Event.COMPLETE (using:- "this.dispatchEvent(new Event(Event.COMPLETE));" )
 */

 package {

    public class ExampleSwf extends MovieClip {

        [Embed(source="movie.swf")] private var MovieSwf:Class;

        private var movie:MovieClipAsset;

        public function ExampleSwf() {
            this.addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event):void {
            this.removeEventListener(Event.ADDED_TO_STAGE, init);

            this.movie = new MovieSwf();
            this.addChild(this.movie);
            this.movie.addEventListener(Event.COMPLETE, onMovieComplete);
        }

        private function onMovieComplete(e:Event):void {
            var foo:String = "bar";
        }

    }

 }

Does anyone know why the event dispatched from the embedded swf is never picked up by the listener?

Thanks :)


I managed to get this to work by using:

stage.dispatchEvent(new Event(Event.COMPLETE));

In my embedded movie.swf file, and then in my as3 class using:

this.movie.stage.addEventListener(Event.COMPLETE, onMovieComplete);


When you embed the movie, it will be ready by time you are creating the instance and add it to the stage. You do not need to listen for the COMPLETE event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜