zoukankan      html  css  js  c++  java
  • 关于事件机制的理解

    最近终于把事件机制弄明白了。和大家分享一下。

    下面是定义的事件:

    package
    {
    	import flash.events.Event;
    	
    	
    	public class NBEEvent extends Event
    	{
    		/**
    		 * 对
    		 */
    		public static const RIGHT: String = "nbe_event_right";
    		
    		
    		
    		public function NBEEvent(type: String, bubbles: Boolean = true, cancelable: Boolean = false)
    		{
    			super(type, bubbles, cancelable);
    		
    		}
    		
    		public override function clone(): Event
    		{
    			return new NBEEvent(type, bubbles, cancelable);
    		}
    		
    		public override function toString(): String
    		{
    			return formatToString("NBEEvent", "type", "bubbles", "cancelable", "eventPhase");
    		}
    	
    	}
    
    }
    

     然后用一个按钮来发送事件

    import NBEEvent;
    import flash.events.MouseEvent;
    
    btn.addEventListener(MouseEvent.CLICK,onClick);
    function onClick(e:MouseEvent)
    {
    	dispatchEvent(new NBEEvent(NBEEvent.RIGHT,false,false));
    }
    

     用一个mc来接收事件

    import NBEEvent;
    m1.addEventListener(NBEEvent.RIGHT,_onRW,false,0,true);
    function _onRW(e:NBEEvent)
    {
    	trace(e.type)
    }
    
  • 相关阅读:
    [ARC117F]Gateau
    [ARC117D]Miracle Tree
    [loj3504]支配
    [gym102511K]Traffic Blights
    [loj3501]图函数
    [loj3503]滚榜
    [loj3500]矩阵游戏
    [loj2135]幻想乡战略游戏
    [cf720D]Slalom
    [cf1349E]Slime and Hats
  • 原文地址:https://www.cnblogs.com/qshuyan/p/3905165.html
Copyright © 2011-2022 走看看