我創建了一個事件處理函數/偵聽器,像這樣:如何在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