View Single Post
Codemonkey's Avatar Codemonkey Codemonkey is offline Super Moderator 2006-11-15 #29 Old  
026 - Listening in on the listeners
 
If you use the EventDispatcher to allow listeners to listen for events on your object, your object gets a list for these listeners and a bunch of functions like dispatchEvent etc. To access this array of listeners, use the property "__q_" on your object. This is the name of the array the EventDispatcher adds to your object:

Setting up the event dispatching object and a listener:

ActionScript Code:
  1. import mx.events.EventDispatcher;
  2. var eventsource:Object = new Object();
  3. EventDispatcher.initialize(eventsource);
  4.  
  5. var listener = new Object();
  6. listener.foo = function (eventObj:Object) {
  7.         trace(eventObj.message); // "I like apple pie!"
  8. }
  9.  
  10. eventsource.addEventListener("foo", listener);
  11. eventsource.dispatchEvent({type:"foo", target:this, message:"I like apple pie!"});
Get access to the array of listeners:

ActionScript Code:
  1. trace(eventsource["__q_" + "foo"] instanceof Array); // traces "true"
  2. trace(eventsource["__q_" + "foo"].length); // traces "1"
  3.