当鼠标单击触发时如何停止 mouse_out 触发
我的按钮具有 mouse_over、mouse_out 和 CLICK 事件。但是当我单击按钮时,它会将我带到另一个框架,并且 mouse_out 事件尝试触发。我该如何阻止这种情况发生?
act1_btn.addEventListener(MouseEvent.CLICK, act1Pressed);
act1_btn.addEventListener(MouseEvent.MOUSE_OVER, act1Over);
act1_btn.addEventListener(MouseEvent.MOUSE_OUT, act1Out);
act1_btn.addEventListener(Event.ENTER_FRAME, act1EnterFrame);
function act1Over(e:MouseEvent):void
{
trace("over");
act1Animating = true;
logo_1.visible = true;
bubble.visible = true;
txt1.visible = true;
}
function act1Out(e:MouseEvent):void
{
act1Animating = false;
logo_1.visible = false;
bubble.visible = false;
txt1.visible = false;
}
function act1EnterFrame(e:Event):void
{
if (act1Animating && e.target.scaleY < 1.1)
{
e.target.scaleY += 0.02;
e.target.scaleX += 0.02;
}
if (!act1Animating && e.target.scaleY > 1)
{
e.target.scaleY -= 0.02;
e.target.scaleX -= 0.02;
}
}
function act1Pressed(e:MouseEvent):void
{
trace("clicked");
act1Animating = false;
logo_1.visible = false;
bubble.visible = false;
txt1.visible = false;
gotoAndStop(2);
}
I have buttons that have mouse_over, mouse_out and CLICK events. But when I click the button it takes me to another frame and the mouse_out event tried to fire. How do I stop that happening?
act1_btn.addEventListener(MouseEvent.CLICK, act1Pressed);
act1_btn.addEventListener(MouseEvent.MOUSE_OVER, act1Over);
act1_btn.addEventListener(MouseEvent.MOUSE_OUT, act1Out);
act1_btn.addEventListener(Event.ENTER_FRAME, act1EnterFrame);
function act1Over(e:MouseEvent):void
{
trace("over");
act1Animating = true;
logo_1.visible = true;
bubble.visible = true;
txt1.visible = true;
}
function act1Out(e:MouseEvent):void
{
act1Animating = false;
logo_1.visible = false;
bubble.visible = false;
txt1.visible = false;
}
function act1EnterFrame(e:Event):void
{
if (act1Animating && e.target.scaleY < 1.1)
{
e.target.scaleY += 0.02;
e.target.scaleX += 0.02;
}
if (!act1Animating && e.target.scaleY > 1)
{
e.target.scaleY -= 0.02;
e.target.scaleX -= 0.02;
}
}
function act1Pressed(e:MouseEvent):void
{
trace("clicked");
act1Animating = false;
logo_1.visible = false;
bubble.visible = false;
txt1.visible = false;
gotoAndStop(2);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有两种方法可以处理此问题:
1) 仅在 MOUSE_OVER 处理程序中分配 MOUSE_OUT 侦听器,然后在 MOUSE_OUT 处理程序完成后将其删除。即,
2) 在您的 CLICK 处理程序中使用 stopPropagation() :
另外,以后请使用代码标签来标记您的代码!
Here are two ways to handle this:
1) Only assign the MOUSE_OUT listener in the MOUSE_OVER handler, then remove it after the MOUSE_OUT handler is done. I.e.,
2) Use stopPropagation() in your CLICK handler:
Also, in the future, please use code tags to mark up your code!
尝试一下 ROLL_OVER 和 ROLL_OUT MouseEvent 可能不是一个坏主意。当有人滚过物体或滚出时,它们只会发射一次,而不是连续发射。
It might not be a bad idea to give ROLL_OVER and ROLL_OUT MouseEvent a shot instead. These just fire once when someone rolls over the object, or rolls out, instead of firing continuously.
当您单击按钮时,您将触发 MouseOver & 按钮。 MouseOut 事件,如果您不希望在 Click 事件之后触发 MouseOut 事件,那么您应该在 Click 事件监听器中删除 MouseOut 事件监听器。
这意味着,为了确保在 MouseOver 时有 MouseOut 侦听器,您应该在 MouseOver 侦听器中添加 MouseOut 侦听器。
最后,您应该删除 MouseOut 侦听器中的 MouseOut 事件侦听器。
When you click a button , you will trigger a MouseOver & a MouseOut event , if you don't wish to trigger the MouseOut event after the Click event , then you should remove the MouseOut event listener in the Click event listener.
This means that in order to be sure that you have a MouseOut listener when you MouseOver , you should add your MouseOut listener in the MouseOver listener.
Finally, you should remove the MouseOut event listener within the MouseOut listener.