views:

32

answers:

2

Hi,

I have an application in flex, it has some components out of the box and quite a few of custom components and events.

I want to get all event listeners on a specific component in runtime, I know how to do it with monkey-patching the framework but I do not want to use a monkey patch nor can I rely on this in production.

Is there a way?

+1  A: 

You can't. You could simply use custom components only and override addEventListener to gather the information. I don't really see why monkey patching wouldn't work. Flex is powerful in features but poor in design and I guess you'll have to just live with that.

greetz
back2dos

back2dos
The demand is not to monkey patch, the application's concept is an application consuming another application through SWFLoader and displaying data about it.something like FxSpy only I need the events part as well.
Avi Tzurel
@KensoDev: at that case, your only option is to modify the application before it is loaded to provide the necessary hooks to collect the information you need. this can be done on the AVM2 loading the swf into a ByteArray, modifying it and then loading it into a loader. Or you wait until AVM2 supports AOP with runtime/boottime weaving.
back2dos
+1  A: 

The EventDispatcher has a pretty slim public interface:

  • addEventListener
  • dispatchEvent
  • hasEventListener
  • removeEventListener
  • willTrigger

This means the list of listeners isn't exposed. You can only tell if there is at least one event listener for a particular type of event.

I would re-examine why you need to do what you want to do. In a typical Observer Pattern the listener list isn't meant to be exposed. I have a strong feeling if you are trying to get that list then you are approaching a higher level problem from the wrong direction.

James Fassett
+1. Usually, when this question is asked, the higher level problem is just a memory leak due to unremoved handlers. :)
back2dos
@back2dos maybe that's usually the case I can promise you it's not in my case.I am trying to access a compiled application through an SWFLoader and get all event listeners on a specific objects.the concept is to build somewhat of a testing framework.@James EventDispatcher doesn't help me what so ever. Thanks
Avi Tzurel