2

Run the following code, once with block.mouseEnabled = true, and again with block.mouseEnabled = false, clicking the block once during each run.

var block:Sprite = new Sprite();
block.name = "block";
with(block.graphics){beginFill(0x000000,1);moveTo(0,0);lineTo(100,0);lineTo(100,100);lineTo(0,100);lineTo(0,0);endFill();}
block.mouseEnabled = true; //change to false to see how event target skips root
addChild(block)
stage.addEventListener( MouseEvent.MOUSE_DOWN, mouse_down, false, 0, true );
function mouse_down( e:MouseEvent ):void{trace( e.target );}

Why is "root" skipped as a target? Is this by design? What is or what might be the design reason for this anomaly?

I ask this because it's a clear a break from the normal pattern where when the child object has mouseEnabled set to false, the parent becomes the target when it's child area is clicked.

It may be that the root is simply a non-participant endpoint in the event capture/target/bubbling rount-trip, and anything that reaches it gets applied to stage instead of root.

Triynko
  • 18,766
  • 21
  • 107
  • 173
  • 2
    **Moderator Note** *Comments under this question were purged because they dissolved into pure noise, zero signal. Please avoid extended discussions or arguments in comments, use chat instead.* – Tim Post Mar 14 '12 at 05:25
  • It's interesting really. You can manually dispatch a mouse event on the root, and it will bubble to the stage as expected, but no amount of mouse interaction with shapes or graphics attached to or drawn on the root will cause the root to become the target; it always defaults to the stage instead. At the very least, it's nice to know you can draw all over the root without any such graphics interfering with mouse interaction, and effectively functioning as a stage background (rather than a root background). – Triynko Mar 14 '12 at 06:01
  • 3
    See my comments on Martys answer. The root object is relative. In the case of stage, stage.root == stage. That is, it is a circular reference. The object target will never be set to "root" because it already is set to the root, that is, the stage. –  Mar 14 '12 at 06:06
  • 1
    I've removed my answer before @Triynko self-detonates as a result of his own infuriation over it. – Marty Mar 14 '12 at 06:21
  • root is a `DisplayObject` so it cannot get mouse events. To create reusable and maintainable code, you should never access or rely on the root anyway. Just make a background sprite big enough to cover the relevant area. – laurent Apr 06 '12 at 10:40

1 Answers1

1

Any strokes and vector-fills on graphics are not interactive and cant catch interactive events. U can use graphics.beginBitmapFill method or add Bitmap (or any other) as child into.

Alex Koz.
  • 490
  • 8
  • 26