Well, this is something I'll never understand... Why people always use bubbling events to capture events on the stage?
If you look at the doc, event is propagated from the stage to the target object (capture phase) and then bubbles if you enable bubbling.
So ... just use capture :
Main.as
package {
import flash.display.Sprite;
public class Main extends Sprite
{
public function Main()
{
var c:Circle = new Circle();
var r:Rect = new Rect();
c.addChild(r);
addChild(c);
addEventListener(CustomEvent.CUSTOM, customEventHandler, true);//don't forget third parameter to use capture
}
private function customEventHandler(e:CustomEvent):void
{
trace(e.eventPhase == EventPhase.CAPTURING_PHASE);//shows true
}
}
}
Circle.as
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Circle extends Sprite
{
public function Circle()
{
super();
init();
}
private function init():void
{
with(graphics)
{
beginFill(0xFF0000);
drawCircle(25, 25, 50);
endFill()
}
}
}
}
Rect.as
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Rect extends Sprite
{
public function Rect()
{
super();
init();
}
private function init():void
{
with(graphics)
{
beginFill(0x000000);
drawRect(0, 0, 25, 25);
endFill();
}
addEventListener(MouseEvent.CLICK, mouseClickHandler);
}
private function mouseClickHandler(e:MouseEvent):void
{
dispatchEvent(new CustomEvent(CustomEvent.CUSTOM));
}
}
}
CustomEvent.as
package
{
import flash.events.Event;
public class CustomEvent extends Event
{
public static const CUSTOM:String = "custom";
public function CustomEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
}
}