自定义事件类的方法——复合EventDispatcher类

================Main文档类================

package {
	import flash.display.Sprite;
	public class Main extends Sprite {
		public function Main():void {
			var a:MyEventObject=new MyEventObject();
			a.getdispatcher().addEventListener(MouseEvent.CLICK,an);//此处的a.getdispatcher()相当于abc,之所以不直接写a,是因为MyEventObject类未继承EventDispatcher类,不具备addEventListener()侦听方法
			function an(evt:MouseEvent) {
				//代码行,此处省略
			}
		}
	}
}

================MyEventObject发送事件类================

package {
	import flash.events.Event;
	import flash.events.EventDispatcher;
	public class MyEventObject {//注意此处未继承EventDispatcher类
		private var abc:EventDispatcher;
		public function MyEventObject():void {
			abc=new EventDispatcher();//复合EventDispatcher类
		}
		public function getdispatcher():EventDispatcher {
			return abc;
		}
		public function doevent():void {
			abc.dispatchEvent(new Event());//手动触发事件
		}
	}
}
posted @ 2010-04-04 22:55  LT世纪  阅读(243)  评论(0编辑  收藏  举报