Flex4 Custom Event

1、define custom event

package com.amaxgs.framework.events
{
	import flash.events.Event;
	
	public class HandleObjectEvent extends Event
	{
		public static const CLOSE_TYPE:String = "CloseObjectEvent";
		public static const UPDATE_TYPE:String = "UpdateObjectEvent";
		public static const VIEW_TYPE:String = "ViewObjectEvent";
		
		public var obj:Object;
		
		public function HandleObjectEvent(obj:Object,type:String,bubbles:Boolean=false, cancelable:Boolean=false)
		{
			super(type,bubbles,cancelable);
			this.obj=obj;
			
		}
		
		override public function clone():Event {
			return new HandleObjectEvent(obj, type, bubbles, cancelable);
		}
		
	}
}

 2、dispatch event

<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
								  xmlns:s="library://ns.adobe.com/flex/spark" 
								  xmlns:mx="library://ns.adobe.com/flex/mx" 
								  focusEnabled="true">

	<fx:Script>
		<![CDATA[
			import com.amaxgs.framework.events.HandleObjectEvent;
			import com.amaxgs.internals.view.currentTask.ActionItemEditPanel;
			import com.amaxgs.internals.view.currentTask.QuestionEditPanel;
			import com.amaxgs.internals.view.currentTask.RiskEditPanel;
			import com.amaxgs.internals.vo.ActionItemVo;
			import com.amaxgs.internals.vo.QuestionVo;
			import com.amaxgs.internals.vo.RiskVo;
			
			import mx.core.FlexGlobals;
			import mx.managers.PopUpManager;
			
			import org.flintparticles.common.actions.Action;
			private function clickCloseHandler(event:MouseEvent):void
			{
				var obj:Object=this.data;
				this.dispatchEvent(new HandleObjectEvent(obj,HandleObjectEvent.CLOSE_TYPE,true));
			}
			
			private function clickUpdateHandler(event:MouseEvent):void
			{
				var obj:Object=this.data;
				this.dispatchEvent(new HandleObjectEvent(obj,HandleObjectEvent.UPDATE_TYPE,true));
			}
			
			private function clickViewHandler(event:MouseEvent):void
			{
				var obj:Object=this.data;
				this.dispatchEvent(new HandleObjectEvent(obj,HandleObjectEvent.VIEW_TYPE,true));
			}
		]]>
	</fx:Script>

	<mx:LinkButton textDecoration="underline" label="Close" click="clickCloseHandler(event)" x="2"/>
	<mx:LinkButton textDecoration="underline" label="Update" click="clickUpdateHandler(event)" x="47"/>
	<mx:LinkButton textDecoration="underline" label="View" click="clickViewHandler(event)" x="102"/>
</s:MXAdvancedDataGridItemRenderer>

 

3、Add event listener

  

this.addEventListener(HandleObjectEvent.CLOSE_TYPE, closeObjectHandler);
				
this.addEventListener(HandleObjectEvent.UPDATE_TYPE, updateObjectHandler);

 

你可能感兴趣的:(event)