Fran Verona
Fran Verona

Reputation: 5476

Trigger event from child to parent in AS3

I have a MovieClip with a MouseEvent function associated to CLICK event. Inside of this MovieClip I have a TextField.

So, when I click on my MovieClip, the handler works fine. Now I need the same behaviour when I click on this TextField, but without change my handler function. I mean, I don't want to change e.target to e.target.parent if user clicked on TextField instead of MovieClip.

How can I do this?

Some of my source code:

public function Main(){
   var m = new menu();
   menuMng.addChild(m);
   m.addEventListener(MouseEvent.CLICK, openMenu);
}

private function openMenu(e:MouseEvent):void{
   // Do some stuff
}

Thanks in advance!

Upvotes: 0

Views: 1357

Answers (2)

Matteo Vinci
Matteo Vinci

Reputation: 208

You can fix problem setting mouseChildren property to false on MovieClip m. In this case click on textfield will trigger MouseEvent like if user click on m. For clarity:

var m = new menu();
m.mouseChildren = false;
...

I hope this will be usefull to you!

Upvotes: 1

Sly_cardinal
Sly_cardinal

Reputation: 12993

This is a fairly common question - you can use the event.currentTarget property instead of event.target to reference the object to which you added the event listener.

For a more detailed answer check out this question (don't worry about the Flex aspect of it - this relates to standard Actionscript 3 behaviour): What is the difference between target and currenttarget in flex?

Upvotes: 4

Related Questions