views:

241

answers:

1

Is it possible to dispatch an event from an object when an event listener is added to that same object, without overriding the addEventListener method of that class?

I am working on a modularized application in AS3. Several of the modules register events on a component in the main application mxml file. I would like to fire an event anytime an event is registered to the component from any module, without putting "dispatchEvent(someEvent)" after every addEventListener.

Any input would be greatly appreciated?

+1  A: 

I don't know of any built-in that will help you, but you could just write your own function to encapsulate those.

public static function addEvent(ed:IEventDispatcher, evt:String, handler:Function) {
  ed.addEventListener(evt, handler, false, 0, true);
  ed.dispatchEvent(new Event("addedEvent"));
}
Glenn