包含事件資料的自定義事件
package
{
import flash.events.Event;
public class CustomEvent extends Event
{
public static const START:String = "START";
public static const STOP:String = "STOP";
public var data:*;
public function CustomEvent(type:String, data:*,
bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
if (data)
this.data = data;
}
}
}
要傳送自定義事件:
var dataObject:Object = {name: "Example Data"};
dispatchEvent(new CustomEvent(CustomEvent.START, dataObject))
要收聽自定義事件:
addEventListener(CustomEvent.STOP, stopHandler);
function stopHandler(event:CustomEvent):void
{
var dataObject:* = event.data;
}