从触发事件子父在AS3事件

由网友(你指尖冬夏皆凉)分享简介:我有相关的点击事件的MouseEvent 功能的影片剪辑。在这个影片剪辑的我有一个文本字段。I have a MovieClip with a MouseEvent function associated to CLICK event. Inside of this MovieClip I have a TextFi...

我有相关的点击事件的MouseEvent 功能的影片剪辑。在这个影片剪辑的我有一个文本字段。

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

所以,当我点击我的影片剪辑,该处理程序工作正常。现在我需要相同的行为,当我点击这个文本字段,但是没有改变我的处理函数。我的意思是,我不想改变 e.target e.target.parent 如果用户点击文本字段的影片剪辑代替。

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?

我的一些源$ C ​​$ C:

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!

推荐答案

这是一个相当普遍的问题 - 你可以用 event.currentTarget 属性,而不是将event.target 引用其添加的事件侦听器的对象。

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.

有关更详细的解答看看这个问题(不要担心它的Flex的方面 - 这涉及到标准的ActionScript 3的行为): What是目标和currentTarget当前在柔性之间的区别是什么?

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?

阅读全文

相关推荐

最新文章