Actionscript 3 Actionscript 3.0侦听已调度的自定义事件
我在用侦听器捕获自定义事件时遇到一些问题 我有很多叫做钥匙的东西。单击每个键时,会发送一个自定义事件,如下所示:Actionscript 3 Actionscript 3.0侦听已调度的自定义事件,actionscript-3,events,Actionscript 3,Events,我在用侦听器捕获自定义事件时遇到一些问题 我有很多叫做钥匙的东西。单击每个键时,会发送一个自定义事件,如下所示: public class Key extends Sprite { private var letter:String; public static const CLICKED:String = "clicked"; private function keyClicked(e:MouseEvent):void { this.removeEv
public class Key extends Sprite
{
private var letter:String;
public static const CLICKED:String = "clicked";
private function keyClicked(e:MouseEvent):void {
this.removeEventListener(MouseEvent.CLICK, keyClicked, false);
this.mouseEnabled = false;
dispatchEvent(new Event(CLICKED));
}
}
所有键都是键盘对象的子项。键盘对象的父对象之一具有如下事件侦听器:
addEventListener(Key.CLICKED, keyboardGuess);
哪个叫
public function keyboardGuess(e:Event):void {
trace("event received");
var letter:String = e.target.getLetter();
trace(letter);
} //there will be other functionality in here when I get it listening
然而,虽然我可以说我成功地调度了事件,但我的侦听器从未接收到它。我已经为此疯狂了一个多小时;您能帮我弄清楚发生了什么吗?自定义事件的气泡值应该为true,这样包含Key的对象就可以接收事件。如果bubbles值为false,则只有发送事件的对象才能接收事件,就像您输入的键一样 大约 试一试
dispatchEvent没有将气泡默认为true?没有,因为我正在调度一个默认为false的新事件,这就是为什么我在API中找不到它;我在查看dispatchEvent,而不是事件构造函数。这正好解决了我的问题。非常感谢你!
dispatchEvent(new Event(CLICKED, true));