e.target和e.currentTarget的区别 [英] Difference between e.target and e.currentTarget
问题描述
我不理解上的差异,他们似乎都一样,但我猜他们不是。
I don't understand the difference, they both seem the same but I guess they are not.
当使用一个或另一个将AP preciated的任何实例。
Any examples of when to use one or the other would be appreciated.
推荐答案
本是完全正确的在他的答案 - 所以要什么,他说,在脑海。我要告诉你的是不是一个完整的解释,但它是一个非常简单的方法来记得 e.target
, e.currentTarget什么
工作有关鼠标事件,并显示列表:
Ben is completely correct in his answer - so keep what he says in mind. What I'm about to tell you isn't a full explanation, but it's a very easy way to remember how e.target
, e.currentTarget
work in relation to mouse events and the display list:
e.target
=鼠标下的东西(如本说...触发事件的东西)。
e.currentTarget
=点前......(见下文)的事
e.target
= The thing under the mouse (as ben says... the thing that triggers the event).
e.currentTarget
= The thing before the dot... (see below)
所以,如果你有btns的实例名称的剪辑中的10个按钮,你做的:
So if you have 10 buttons inside a clip with an instance name of "btns" and you do:
btns.addEventListener(MouseEvent.MOUSE_OVER, onOver);
// btns = the thing before the dot of an addEventListener call
function onOver(e:MouseEvent):void{
trace(e.target.name, e.currentTarget.name);
}
e.target
将是10个按钮之一, e.currentTarget
将永远是btns剪辑。
e.target
will be one of the 10 buttons and e.currentTarget
will always be the "btns" clip.
值得一提的是,如果你改变了MouseEvent来一个ROLL_OVER或设置属性 btns.mouseChildren
为false, e.target
和 e.currentTarget
都将永远是btns。
It's worth noting that if you changed the MouseEvent to a ROLL_OVER or set the property btns.mouseChildren
to false, e.target
and e.currentTarget
will both always be "btns".
这篇关于e.target和e.currentTarget的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!