`
DavyJones2010
  • 浏览: 151910 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Flex: How to create a custom Event

    博客分类:
  • Flex
阅读更多

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;
		}
	}
}

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics