Navigation

Previous

Archives

2007年5月6日 @ 20:25

Calling Event Handlers without Events[转贴]

Calling Event Handlers without Events

 

 


转贴:http://typhone918.blogspot.com/2007/05/calling-event-handlers-without-events.html
When you define event handlers in ActionScript 3, the functions need to accept 1 parameter of the type Event. When these methods are called by the events, those event objects are then passed into the handler.

If you have an event handler that you want to use as a normal function call, you can call that function with a new Event object passed into it like so:

 

 

ActionScript Code:

 

 

myHandler(new Event(someEventType));

 

 


However, that can be a hassle and a little confusing (plus you are creating an event that probably has nothing to do with the function). If you just want to be able to call the event handler without having to worry about that event but still have it work for calls coming from events, you can define the handler with your event parameter having a default value of null. This way you can call the function without an event but still have it work when the event is passed from an actual event call.

 

 

ActionScript Code:

 

 

public function myHandler(event:Event = null):void {...}
...
// call normally without event
myHandler();

 

 


Note: this will not work if your event handler relies on information from the event object.

 

 

 

 


Share

Filed under: 资料 · Tags: flex  

Articles related:

Flex2.01:基于模块的flex应用开发  (2007-5-5 11:26:37)

AS3的png图片编码器  (2007-5-5 11:24:10)

The Flex Style Explorer is a Proud Papa  (2007-4-12 11:3:42)

Flex Effects Explorer  (2007-3-12 17:26:37)

Leave a Comment

◎welcome to give out your point。

Misc

Linkage