0

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!

Fran Verona
  • 5,438
  • 6
  • 46
  • 85

2 Answers2

4

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?

Community
  • 1
  • 1
Sly_cardinal
  • 12,270
  • 5
  • 49
  • 50
1

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!

Matteo Vinci
  • 208
  • 2
  • 12