• 带参数的EventDispatcher


    //首先  先写一个自定义的EventDisplay的类 继承Event
    package gameCode.ui.SecondLayer.onlinePlayer
    {
    	import flash.events.Event;
    	
    	public class OnlineEventDisplay extends Event
    	{
    		//需要监听的类
    		static public const WANJIA_ITEM_CLICK:String="WANJIA_ITEM_CLICK";
    	 	
    		//我有3个事件需要派发 所以就写了3个常量
    		static public const WANJIA_SILIAO_ITEM_CLICK:String="WanJia_SiLiao_ITEM_CLICK";
    		
    		static public const WANJIA_ADD_ITEM_CLICK:String="WanJia_Add_ITEM_CLICK";
    		
    		static public const WANJIA_ZUDUI_ITEM_CLICK:String="WanJia_ZuDui_ITEM_CLICK";
    		
    		//这里是用来传入我用来判断的类别 
    		public var leibie:String="";
    		
    		
    		//这个data是用来传入你想传入的参数
    		public var data:Object;
    		
    		
    		//注意 这里需要把冒泡设为true;
    		public function OnlineEventDisplay(type:String, bubbles:Boolean=true, cancelable:Boolean=true)
    		{
    			super(type, bubbles, cancelable);
    		}
    		
    		//复写clone方法 把data内的数据放入事件内置的data里
    		override public function clone():Event
    		{
    			var e:OnlineEventDisplay=new OnlineEventDisplay(type,bubbles,cancelable);
    			e.data=this.data;
    			return e;
    		}
    		
    	}
    }
    

      

    发送的地方
    private var data:Object;
    
    
    
    hatredIcon.addEventListener(MouseEvent.CLICK,onhatredIconClickHandler);
    				plusIcon.addEventListener(MouseEvent.CLICK,plusIconClickHandler);
    				icon.addEventListener(MouseEvent.CLICK,iconClickHanlder);
    
    
    
    protected function onhatredIconClickHandler(event:MouseEvent):void
    			{
    				var e:OnlineEventDisplay = new OnlineEventDisplay(OnlineEventDisplay.WANJIA_ITEM_CLICK);
    				e.data = this.data;
    				e.leibie=OnlineEventDisplay.WANJIA_SILIAO_ITEM_CLICK;
    				this.dispatchEvent(e);
    			}
    			
    			protected function plusIconClickHandler(event:MouseEvent):void
    			{
    				
    				var e:OnlineEventDisplay = new OnlineEventDisplay(OnlineEventDisplay.WANJIA_ITEM_CLICK);
    				e.data = this.data;
    				e.leibie=OnlineEventDisplay.WANJIA_ADD_ITEM_CLICK;
    				this.dispatchEvent(e);
    			}
    			protected function iconClickHanlder(event:MouseEvent):void
    			{
    				var e:OnlineEventDisplay = new OnlineEventDisplay(OnlineEventDisplay.WANJIA_ITEM_CLICK);
    				e.data = this.data;
    				e.leibie=OnlineEventDisplay.WANJIA_ZUDUI_ITEM_CLICK;
    				this.dispatchEvent(e);
    			}
    

      

      

    接收的地方
    protected function basebg1_contentCreationCompleteHandler(event:FlexEvent):void
    			{
    				onlinePlayer_List.addEventListener(OnlineEventDisplay.WANJIA_ITEM_CLICK,ItemClickHandle);
    			}
    			
    			protected function ItemClickHandle(event:OnlineEventDisplay):void
    			{
    				if(event.leibie == OnlineEventDisplay.WANJIA_SILIAO_ITEM_CLICK)
    				{
    					onLinePlayerPanelEvent.dispatch("WANJIA_SILIAO_ITEM_CLICK",event.data.id);
    					event.stopImmediatePropagation();
    				}
    				if(event.leibie == OnlineEventDisplay.WANJIA_ADD_ITEM_CLICK)
    				{
    					onLinePlayerPanelEvent.dispatch("WANJIA_ADD_ITEM_CLICK",event.data.id);
    					event.stopImmediatePropagation();
    				}
    				if(event.leibie == OnlineEventDisplay.WANJIA_ZUDUI_ITEM_CLICK)
    				{
    					onLinePlayerPanelEvent.dispatch("WANJIA_ZUDUI_ITEM_CLICK",event.data.id);
    					event.stopImmediatePropagation();
    				}
    			}
    

      

  • 相关阅读:
    秋风下的萧瑟 NOIP2018 游记
    Dsu on Tree
    BZOJ 3812 : 主旋律
    FFT&NTT
    manacher
    Winniechen’s test1
    如何在万亿级别规模的数据量上使用Spark
    Spark运行时的内核架构以及架构思考
    hadoop离线数据存储和挖掘架构
    Hadoop平台的基本组成与生态系统
  • 原文地址:https://www.cnblogs.com/sinsoul/p/2261396.html
Copyright © 2020-2023  润新知