import mx.controls.Alert;
import flash.events.MouseEvent;
button 事件注册
internal function iniAPP():void{
bt1.addEventListener(MouseEvent.CLICK,onc);
bt1.addEventListener(MouseEvent.MOUSE_MOVE,onm);
//bt1.addEventLister(事件类型,要执行的方法名,是否捕获,优先级-从0开始从最大值的开始执行);
}
internal function onc(evt:MouseEvent):void{
Alert.show("测试");
txt.text="被点击了。";
}
internal function onm(evt:MouseEvent):void{
txt2.text+="经过了。。。\n";
}
事件发布:
internal function iniAPP():void{
bt1.addEventListener(MouseEvent.CLICK,cl);
bt1.addEventListener("testEvent",ol);
}
internal function cl():void{
//do something
bt1.dispatchEvent(new Event("testEvent",true,false));//dispatchEvent发布自己的事件;
}
//自定事件中的方法
internal function ol():void{
Alert.Show("自定事件的方法");
}
先注册MouseEvent.CLICK事件,调用cl方法,通过cl方法发布一个testEvent事件,再通过testEvent事件调用ol方法。