当鼠标单击触发时如何停止 mouse_out 触发

发布于 2024-09-28 00:48:04 字数 1156 浏览 1 评论 0原文

我的按钮具有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝梦月影 2024-10-05 00:48:04

有两种方法可以处理此问题:

1) 仅在 MOUSE_OVER 处理程序中分配 MOUSE_OUT 侦听器,然后在 MOUSE_OUT 处理程序完成后将其删除。即,

function act1Over(e:MouseEvent):void {
  /* your code */
  act1_btn.addEventListener(MouseEvent.MOUSE_OUT, act1Out); 
}

function act1Out(e:MouseEvent):void {
  /* your code */
  act1_btn.removeEventListener(MouseEvent.MOUSE_OUT, act1Out); 
}

2) 在您的 CLICK 处理程序中使用 stopPropagation()

function act1Pressed(e:MouseEvent):void {
  /* your code */
  e.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.,

function act1Over(e:MouseEvent):void {
  /* your code */
  act1_btn.addEventListener(MouseEvent.MOUSE_OUT, act1Out); 
}

function act1Out(e:MouseEvent):void {
  /* your code */
  act1_btn.removeEventListener(MouseEvent.MOUSE_OUT, act1Out); 
}

2) Use stopPropagation() in your CLICK handler:

function act1Pressed(e:MouseEvent):void {
  /* your code */
  e.stopPropagation();
}

Also, in the future, please use code tags to mark up your code!

执笏见 2024-10-05 00:48:04

尝试一下 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.

心房敞 2024-10-05 00:48:04

当您单击按钮时,您将触发 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文