Reputation: 18956
I know the different between event capturing and bubbling and how stopPropagation
work.
So why capturing not worked in my simple test? There is no stopPropagation
in the code.
import flash.display.Sprite;
import flash.events.MouseEvent;
public class CapturingNotWork extends Sprite {
public function CapturingNotWork() {
var rect:Sprite = new Sprite();
rect.graphics.beginFill(0x000000);
rect.graphics.drawRect(0, 0, 100, 100);
rect.graphics.endFill();
// CAPTURING NOT WORKED
rect.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown, true);
// BUT THE BUBBLING WORKED
// rect.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
stage.addChild(rect);
}
function mouseDown(e:MouseEvent): void {
trace("It's worked");
}
}
Upvotes: 0
Views: 135
Reputation: 11395
The event starts with the topmost parent (stage) and works down the display object hierarchy until reaching the original target.
When the useCapture parameter is set to true, the listener processes the event only during the capture phase and not in the target or bubbling phase. Your event never reaches the target (rect) as you can see on this image:
Upvotes: 1