Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get all of that requires a little bit of a hack. You have to store whether the mouse is off the stage or not and handle the <code>Event.MOUSE_LEAVE</code> event accordingly. Doing it this way gives you all the normal mouse functionality including not stopping the drag just because the mouse went off stage. Since the user might come back on stage and continue the drag it waits 'til the user releases the mouse either on or off stage.</p> <pre><code>var mouseOffStage:Boolean; var bonk:YourDisplayObject = new YourDisplayObject() addChild(bonk); bonk.addEventListener(MouseEvent.MOUSE_DOWN, function():void { mouseOffStage = false; bonk.startDrag(); stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp); stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave); stage.addEventListener(MouseEvent.MOUSE_OUT, mouseOut); stage.addEventListener(MouseEvent.MOUSE_OVER, mouseOver); }) private function mouseUp(e:MouseEvent) :void { trace("Mouse Up On Stage") bonk.stopDrag() } private function mouseLeave(e:Event) :void { if(mouseOffStage){ trace("mouse up and off stage"); bonk.stopDrag(); }else{ trace("mouse has left the stage"); //no reason to stop drag here as the user hasn't released the mouse yet } } private function mouseOut(e:MouseEvent) :void { mouseOffStage = true; trace("mouse has left the stage") } private function mouseOver(e:MouseEvent) :void { mouseOffStage = false; trace("mouse has come back on stage"); } </code></pre> <p>The hack is that the <code>MOUSE_LEAVE</code> event, not the <code>MOUSE_UP</code> event, gets fired when the mouse is released off stage so you have to keep track of whether or not the mouse was already off stage when it was released.</p> <p>after the drag is finished you of course want to remove all the event listeners associated with detecting mouse-outs and mouse-ups but that code was left out for readability.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload