Flex: How to create a custom Event

1. Create a subclass that extends the flash.events.Event base class

2. Add properties to the subclass to hold the data you want to dispatch

3. Create the event class's constructor:

        3.1 Invoke the super() method of the Event class within the constructor, passing the event type to it

        3.2 Populate the class properties from the constructor arguments

4. Override the clone() method of the event class with the new subclass.

 

Attention:

The constructor should do at least 4 things:

         1. Accept an argument for the event type

         2. Accept arguments for the data you want to pass

         3. Call the super() method

         4. Populate the class properties from the arguments

 

Eg.

 

package event
{
	import flash.events.Event;
	
	import valueObjects.Employee;

	public class ShowPreview extends Event
	{
		public var employee:Employee;	//Data for transfer
		public var message:String;		//Data for transfer
		
		public function ShowPreview(type:String, employee:Employee, message:String)
		{
			super(type);				//type info: can be Event.CLICK or custom event type defined in <metadata>
			
			this.employee = employee;
			this.message = message;
		}
	}
}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值