如何寻址已被单击的对象而不是其中的子对象?
在 MouseEvent.CLICK 函数中,我通常使用 e.target 来寻址我单击的 movieClip,但这只适用于内部没有任何子项(例如文本和其他符号)的 movieClip。当它内部有子级时,e.target 返回 Mc 内的子级,但不返回 Mc 本身。 e.currentTarget 也不起作用;它返回 [object MovieClip] 但不返回 Mc 的实例名称。无论如何我可以修复它吗? 谢谢。
inside a MouseEvent.CLICK function, I usually used e.target to address the movieClip that I clicked, but that only work with a movieClip that doesn't have any children (such as text and other symbols) inside. When it has children inside, the e.target return the child inside the Mc but not the Mc itself. The e.currentTarget didn't work, either; it returned [object MovieClip] but not the instance name of the Mc. Is there anyway I can fix it?
thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要获取实例名称,您需要
e.currentTarget.name
。To get the instance name you would need
e.currentTarget.name
.e.target
= 已被单击的元素。e.currentTarget
= 已注册侦听器的元素。假设一个红色框包含一个蓝色框:
如果您单击红色框(位于内部蓝色框之外):
e.target
= rede.currentTarget
= red如果您单击蓝色框:
e.target
= bluee.currentTarget
= red要防止蓝框分派点击事件,您可以禁用子元素的鼠标事件:
如果您随后单击蓝色框:
e.target
= 红色e.currentTarget
= 红色e.target
= element that has been clicked.e.currentTarget
= element for that a listener has been registered.Assuming a red box containing a blue box:
If you click the red box (outside the inner blue one):
e.target
= rede.currentTarget
= redIf you click the blue box:
e.target
= bluee.currentTarget
= redTo prevent your blue box dispatching click events you can disable mouse events for child elements:
If you then click the blue box:
e.target
= rede.currentTarget
= red将预期目标的
mouseChildren
设置为false
以阻止事件传播到 MovieClip 的子级中。Set
mouseChildren
of the intended target tofalse
to stop the events propagating into the MovieClip's children.