Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clicking on sprite child triggers its parent's function as well.

Status
Not open for further replies.

maguskrool

Technical User
Dec 11, 2006
77
PT
Hello.

I have this menu item, which is a Sprite. The menu item then has several other items, also Sprite, as children. All items have a listener for click events. When I click the parent item, it's all ok, but when I click one of the children, both the child and the parent Sprite's event handler functions are triggered.

Code:
var myParent:Sprite = new Sprite();
var myChild1:Sprite = new Sprite();
myParent.addChild(myChild1);

function click_parent ($event:MouseEvent) {
trace ("parent clicked");
}
function click_child ($event:MouseEvent) {
trace ("child clicked");
}
myParent.addEventListener(MouseEvent.CLICK, click_parent);
myChild.addEventListener(MouseEvent.CLICK, click_child);

//(Clicking myParent)
//parent clicked

//(Clicking myChild1)
//child clicked
//parent clicked

How can I stop the parent sprite from responding to the click on the child?

Thanks in advance.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top