使用as3中EventDispatcher类
用法大同小异
package{
import flash.events.EventDispatcher;
import flash.events.Event;
//继承EventDispatcher类
class CustomDispatcher extends EventDispatcher {
//事件名
??public static var ACTION:String = "action";
//发出事件的方法
public function doAction():void {
dispatchEvent(new Event(CustomDispatcher.ACTION));
}
}
}
在fla中,
import CustomDispatcher
var evtIns=new CustomDispatcher()
//接收事件
evtIns.addEventListener(CustomDispatcher.ACTION,funcHangler)
function funcHangler(evt:Event){
??//输出事件名
??trace(evt.type)
}
//发出事件
evtIns.doAction()
本文转自:http://www.5uflash.com/flashjiaocheng/Flash-as3-jiaocheng/1794.html