as3.0自定义事件。

今天看到一个容易理解的as3.0自定义事件实例:

package {
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.EventDispatcher;
	public class myClip extends Sprite {
		public function myClip() {
			addEventListener(MouseEvent.CLICK,clickHander);
		}
		private function clickHander(evt:MouseEvent):void {
			
			var _clipEvent:clipEvent=new clipEvent();
			_clipEvent.M="wangyan";
			dispatchEvent(_clipEvent);
		}
	}
}
//库绑定类
package {
	import flash.events.Event;
	public class clipEvent extends Event {
		public static const CLIP_CLICK:String="clip_click";
		private var _mm:String;
		public function clipEvent() {
			super(CLIP_CLICK);
		}
		public function get M() {
			return _mm;
		}
		public function set M(a:String) {
			_mm=a;
		}
	}
}
//自定义事件类
function listen_clipEvent(evt:clipEvent) {
	trace("hello"+evt);
}
abc.addEventListener(clipEvent.CLIP_CLICK,listen_clipEvent);

 

posted @ 2014-07-31 14:12  Andy.Qiu  阅读(415)  评论(0编辑  收藏  举报