I have a base class for buttons which handles button basics like mouse listeners etc.
Now I’m trying to extend it to also have the possibility to store an event (yes event, not event type) that is supposed to be dispatched on click.
So I have my CustomEvent (extending Event) that I pass into the base class and store it with type Event.
Outside, in the event listener I have an event argument typed as CustomEvent.
First time I click it works fine and event is CustomEvent traces *true *in the event handler.
But the second time I click, event is CustomEvent traces *false *and I get the “type coercion failed” error (cannot convert Event to CustomEvent):
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@29d3b7e1 to com.package.events.CustomEvent.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.package.display.buttons::ButtonBase/onClick()
If I trace *event is CustomEvent *in the base class before the event is dispatched it always traces true.
So it seems something happens to the event in the dispatcher functions, but what boggles me is that the base class always sees the event as *CustomEvent *while the event listener thinks it is *CustomEvent *first time only.
Anybody know why?
I know this approach is not the best architecture wise, but I still thinks it’s a bit weird and would like to understand it better.