AS3自定义事件未在文档类上触发(使用DispatchEvent actionscript)

时间:2011-04-28 19:46:36

标签: flash actionscript-3 dispatchevent

我试图通过使用dispatchEvent来了解捕获事件“Beep2”所需的内容。函数“DoNext”没有触发,即使我能够生成dispatchEvent“Beep2 true”的跟踪结果。

此代码使用CustomEvent类来扩展事件类。它到目前为止是我的知识极限,所以任何帮助将不胜感激。 :)

感谢。

包 //Main.as(文档类)

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"); 
    }


}

包 //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 Constructor
    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);
    }
}

包 //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));
    }
}

1 个答案:

答案 0 :(得分:2)

我认为您的问题是,在您添加EventListener之前触发了事件。