Ignore nativeWindow event listener

212 views Asked by At

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. Is there a simple solution?

Any help highly appreciated!

1

There are 1 answers

1
N Rohler On BEST ANSWER

You need to only process the event if the event's target (where it originated from) is the dispatcher you were listening to. The dispatcher is identified via 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();
}

P.S. I notice you're new to Stack Overflow - welcome! If you find my answer useful, please be sure to upvote it and accept it via the green checkmark