e.target 可以用于按钮吗
我没有使用 MouseEvent 分配给每个按钮,而是通过以下方式分配给 AIR 应用程序:
private function init():void {
this.addEventListener(MouseEvent.MOUSE_DOWN,mpressKey);
}
但是,我只希望 mouse_down 在检测到“button”属性而不是 Demo0.WindowedApplicationSkin2.Group3.contentGroup.g4
时执行>(g4 是一个 id)。
Rather than assign to every buttons with MouseEvent, I assign to AIR application with:
private function init():void {
this.addEventListener(MouseEvent.MOUSE_DOWN,mpressKey);
}
However, I only want the mouse_down to execute if it detect a "button" property instead of Demo0.WindowedApplicationSkin2.Group3.contentGroup.g4
(g4 is an id).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要依赖
event.target
来检查按钮是否被单击。目标属性设置为单击的最里面的项目。当您单击某个按钮时,您并不总是单击该按钮;而是单击该按钮。您可能会单击显示标签的文本字段,或背景图像(如果有),或其他一些子皮肤部分等 -target
将设置为此内部项目。如果您希望所有按钮都有一个单击处理程序,并根据单击的按钮采取适当的操作,您可以为每个按钮分配与处理程序相同的函数并检查
event.currentTarget
属性;当调用事件处理程序时,currentTarget
将设置为注册该处理程序的对象。当您使用
airApp.addEventListener
添加单个鼠标处理程序时,currentTarget
将始终是您的airApp
,因此您无法使用它来执行操作作为一个函数来处理所有这些。Don't rely on
event.target
to check if a button was clicked or not. The target property is set to the innermost item that was clicked on. When you click on a button, you're not always clicking on The Button; you might be clicking on the text field that displays the label, or the background image if any, or some other child skinning part etc - thetarget
will be set to this inner item.If you want to have a single click handler for all buttons and take appropriate action based on the button clicked, you can assign same function as handlers for each button and check the
event.currentTarget
property; when an event handler is invoked,currentTarget
is set to the object with which that handler was registered.When you add a single mouse handler using
airApp.addEventListener
, thecurrentTarget
will always be yourairApp
and thus you can't use it to act as a single function to handle them all.您是否想知道如何测试目标是按钮还是特定按钮?
如果它是一个按钮
或者它是一个特定的按钮
Are you asking how to test to see if the target is a Button, or a particular button?
If it's a Button
or if it's a particular button