This class was my solution to that problem. Basically have your classes that would normally extend EventDispatcher instead extend BubblingEventDispatcher
and then call the addChildTarget( target:BubblingEventDispatcher ) function to setup children that you can catch bubbled events from.
This solution uses a sprite for each event dispatcher, but results in only 1 byte of extra memory usage per class
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;
public class BubblingEventDispatcher extends EventDispatcher
{
//We have to use a sprite to take advantage of flash's internal event bubbling system
private var sprite:Sprite;
public function BubblingEventDispatcher()
{
//initialize our sprite
sprite = new Sprite();
}
public override function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
{
sprite.addEventListener( type, listener, useCapture, priority, useWeakReference );
}
public override function dispatchEvent(event:Event):Boolean
{
return sprite.dispatchEvent( event );
}
//We must add child targets if we want to take advantage of the bubbling
public function addChildTarget( target:BubblingEventDispatcher ):void
{
sprite.addChild( target.eventTarget as Sprite );
}
public function get eventTarget():EventDispatcher
{
return sprite;
}
}
}