Assuming the following pattern:
someObjectInstance.addEventListener(MyDisplayObject.EVENT_CONSTANT, _handleMyEvent);
private function _handleMyEvent( event:Eve
Wait a minute, everybody. See this answer.
You don't need to customize anything at all to reference the parameter through the listener. So, yes, Gordon, you're able to do this with your average event and event listener.
And it's way simple! The addEventListener function stays the same. Its listener is what will be adjusted:
var functionHandleMyEvent:Function = _handleMyEvent(data);
someObjectInstance.addEventListener(MyDisplayObject.EVENT_CONSTANT, functionHandleMyEvent);
// Later, when you need to remove it, do:
//someObjectInstance.removeEventListener(MyDisplayObject.EVENT_CONSTANT, functionHandleMyEvent);
private function _handleMyEvent(data:Object):Function {
return function(event:Event):void {
if (data == null) {
// Event handler logic here now has both "event" and "data" within your reach
}
}
}
No advanced syntax, but a relatively advanced concept: variable functions. You can do closures with what we have here, but you absolutely won't need to. And like that, you also absolutely won't need to override the Event class.
I hope these examples and documentation are clarifying for you!