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.
0 评论:
发表评论