我创建了一个事件处理函数/侦听器,像这样:如何在ActionScript 3中处理自定义事件?
addEventListener(DanielEvent.APP_STARTED, appStarted);
通过调度事件:
dispatchEvent(new DanielEvent("APP_STARTED", "test"))
和接收数据
import flash.events.Event;
public class DanielEvent extends Event {
public var data:*;
public static const APP_STARTED:String = "APP_STARTED";
public function DanielEvent(n:String, data:*){
this.data = data;
super(n)
}
}
使用聆听事件通过:
private function appStarted(e:Event){
trace(e.data)
}
但我得到的错误:
Access of possibly undefined property data through a reference with static type flash.events:Event.
啊太棒了!感谢您的帮助! – Daniel 2010-10-28 06:10:31