In Flex, is it possible to listen to all event types of an object that's an IEventDispatcher
? addEventListener
's first parameter is the type, which is a string. In many cases the documentation is not clear what event type it fires. I'd like to attach a generic listener to inspect the events.
views:
23answers:
2
A:
I think you have to derive from this class and override the dispatchEvent
method like this:
override public function dispatchEvent(event:Event):Boolean
{
trace(event.type);
return super.dispatchEvent(event);
}
splash
2010-10-06 18:45:54
A:
The short answer is no, there isn't any built-in way of generically listening for all event types. You would either have to develop a system for managing this or do something similar to what splash suggested. Personally, I would create a custom event, override dispatchEvent, and dispatch your own custom event while passing the 'type' of the original event.
override public function dispatchEvent(event:Event):Boolean
{
//Dispatch your custom event passing along with it the type of the original event.
super.dispatchEvent(new CustomEvent(CustomEvent.ALL, event.type);
return super.dispatchEvent(event);
}
Then you could simply setup one listener for your custom event and easily track when and what events are firing.
Hope that helps.
TheoryNine
2010-10-08 15:50:28