e.target 和 e.currentTarget 的区别 [英] Difference between e.target and e.currentTarget

查看:39
本文介绍了e.target 和 e.currentTarget 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白其中的区别,它们看起来一样,但我想它们不是.

I don't understand the difference, they both seem the same but I guess they are not.

任何有关何时使用其中之一的示例将不胜感激.

Any examples of when to use one or the other would be appreciated.

推荐答案

Ben 的回答完全正确 - 所以记住他所说的话.我要告诉你的不是一个完整的解释,但这是记住 e.targete.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)

因此,如果您的剪辑中有 10 个按钮的实例名称为btns",并且您这样做了:

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.targete.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆