Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash AS3 EventDispatcher - any way of getting a list of registered listeners?

Is there any way of getting a list of registered listeners for an EventDispatcher?

I know that EventDispatcher has the hasEventListener method to tell you if any listeners are registered, but is there an easy way of interrogating the EventDispatcher to find out what the listeners are?

One way I figured to do this was to subclass EventDispatcher to override the addEventListener method and store the listeners in a dictionary, but this feels clunky to me.

Any ideas?

like image 785
Reuben Avatar asked Sep 21 '09 01:09

Reuben


2 Answers

Ok, so it seems that there is no answer to this question other than my original idea of storing listeners in a Dictionary and removing them explicitly. Oh well...

Some interesting thoughts about the intricacies AS3 Events system can be found here.

like image 77
Reuben Avatar answered Nov 04 '22 22:11

Reuben


It doesn't look like this is a complete solution but it might help you on your way:

http://www.rialvalue.com/blog/2009/09/08/does-an-eventdispatcher-have-subscribed-listeners/

From the article:

The example above shows how we can get a reference to the different listeners declared in an EventDispatcher and how to remove them without having a direct reference (and knowing the event name arggg).

Even though this can help you to figure out if an EventDispatcher has listeners or not there’re still several problems you might find:

* You don’t have any information about the listener
* You don’t know which event the listener is listening to
* We don’t know which phase the listener is listening to
* Haven’t done too much testing around this, but I think both weak and strong references are hold in the list
* The other thing to consider is that flash.sampler.getMemberNames only works in the debugger version of the Flash Player
like image 41
Ryan Guill Avatar answered Nov 04 '22 21:11

Ryan Guill