简体   繁体   English

忽略nativeWindow事件监听器

[英]Ignore nativeWindow event listener

This has been bugging me for days, cant seem to get an answer after googling forever... 这已经困扰了我好几天了,永远搜寻一次后似乎无法得到答案...

Problem is simple, 问题很简单,

I have a rectangle with an event listener like so: 我有一个带有事件监听器的矩形,如下所示:

rect.addEventListener(MouseEvent.MOUSE_DOWN, startMove);

private function startMove(event:MouseEvent):void
{
    this.nativeWindow.startMove();
}

this works fine. 这很好。

I also have a button inside this rectangle, and when I click the button the window drags just like if I had clicked on the rectangle. 我在此矩形内也有一个按钮,当我单击该按钮时,窗口将拖动,就像单击矩形一样。

How can I stop this from happening? 我该如何阻止这种情况的发生? I tried removing the event but that didn't work, I don't even know which event to remove, the mouseDown or NativeDrag event... There is no stopDrag() function in nativeWindow. 我尝试删除该事件,但是没有用,我什至不知道要删除哪个事件,mouseDown或NativeDrag事件... nativeWindow中没有stopDrag()函数。 Is there a simple solution? 有没有简单的解决方案?

Any help highly appreciated! 任何帮助,高度赞赏!

You need to only process the event if the event's target (where it originated from) is the dispatcher you were listening to. 仅当事件的target (事件的来源)是您正在侦听的调度程序时,才需要处理事件。 The dispatcher is identified via event.currentTarget . 通过event.currentTarget标识调度程序。 So this is what your code needs to look like: 因此,您的代码应如下所示:

rect.addEventListener(MouseEvent.MOUSE_DOWN, startMove);

private function startMove(event:MouseEvent):void
{
   if (event.target == event.currentTarget)
      this.nativeWindow.startMove();
}

PS I notice you're new to Stack Overflow - welcome! PS:我注意到您是Stack Overflow的新手-欢迎光临! If you find my answer useful, please be sure to upvote it and accept it via the green checkmark 如果您发现我的答案有用,请务必对其进行投票并通过绿色的选中标记接受它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM