Yes, very simple, set:

parentSprite.mouseChildren = false;




-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
[email protected]
Sent: maandag 29 maart 2010 5:46
To: Flash Coders List
Subject: [Flashcoders] Prevent children from listening to parent mouse
events

Hey list,

I'm surprised I didn't notice this behaviour sooner, and I wonder how to get
around it.

Suppose you have a parent sprite and a child sprite. The child is small
enough to fit within the parent. The parent has a mouseOut event listener.
It seems that the child sprite's mouseOuts are also listened for, although
the mouse is still within the parent.

Is it possible to listen ONLY for the parent's mouse events, not the
child's?

Example code:

var parentSprite:Sprite = new Sprite();
addChild(parentSprite);
parentSprite.graphics.beginFill(0xFF0000);
parentSprite.graphics.drawRect(0, 0, 100, 100);
parentSprite.name = "parental"

var childSprite:Sprite = new Sprite();
parentSprite.addChild(childSprite);
childSprite.graphics.beginFill(0x0000FF);
childSprite.graphics.drawRect(0, 0, 20, 20);
childSprite.x = childSprite.y = 30;
childSprite.name = "kiddie";

parentSprite.addEventListener(MouseEvent.MOUSE_OUT, mouseHandler)

function mouseHandler (e:MouseEvent):void {
    trace("e.target.name: " + e.target.name)
    trace("e.currentTarget.name: " + e.currentTarget.name)
    trace("")
}
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Geen virus gevonden in het binnenkomende-bericht.
Gecontroleerd door AVG - www.avg.com 
Versie: 9.0.791 / Virusdatabase: 271.1.1/2776 - datum van uitgifte: 03/28/10
20:32:00

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to