开发者

AS3 Custom Event not firing on Document Class ( using DispatchEvent actionscript)

Im trying to get my head round what is needed to catch event "Beep2", using dispatchEvent. The function "DoNext" is not firing, even though Im able to produce a trace result of the dispatchEvent "Beep2 true".

This code uses a CustomEvent Class to Extend the Event Class. Its right on my limit of knowledge so far, so any help would be appreciated. :)

Thanks.

package //Main.as (Document class)

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

public class Main extends MovieClip 
{
    public var ftasks:MovieClip;
    public function Main () 
    {
        ftasks = new filetasks();
        addChild(ftasks);
        ftasks.addEventListener(CustomEvent.BEEP2, DoNext);
    }

//not firing
    public function DoNext (evt:Event) 
{
        trace("DoNext"); 
    }


}

package //CustomEvent.as

//Extend Event class.
import flash.events.Event;
public class CustomEvent extends Event
{
    public static const BEEP1 ="Beep1";
    public static const BEEP2 ="Beep2";

    //Declare Event C开发者_运维知识库onstructor
    public function CustomEvent(type:String, bubbles:Boolean)
    {
        super(type, bubbles);
        type = this.type;
        bubbles = this.bubbles;
        trace(type, bubbles);
    }

    public override function clone():Event
    {
        return new CustomEvent(type, bubbles);
    }
}

package //filetasks.as

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;

public class filetasks extends MovieClip 
{
    public var Ref;

    public function filetasks (_Ref) 
    {
        Ref = _Ref;
        dispatchEvent(new CustomEvent(CustomEvent.BEEP2, true));
    }

    public function done (evt:MouseEvent) 
    {
        dispatchEvent(new CustomEvent(CustomEvent.BEEP1, true));
    }
}


I think your problem is, that the event is fired, before you even added the EventListener.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜