1

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

此代码使用 CustomEvent 类来扩展事件类。到目前为止,它在我的知识范围内是正确的,因此将不胜感激。:)

谢谢。

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

1 回答 1

2

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

于 2011-04-28T20:00:20.637 回答