开发者

Flash: Tracking mouse position after click-and-drag (down-and-move), even outside the stage/browser?

开发者 https://www.devze.com 2023-02-10 22:12 出处:网络
What\'s the correct way to track mouse position, from Adobe Flash, when someone has: Started a drag within the Flash application (a MOUSE_DOWN event),

What's the correct way to track mouse position, from Adobe Flash, when someone has:

  1. Started a drag within the Flash application (a MOUSE_DOWN event),
  2. Dragged the mouse outside the app or even the browser window (a MOUSE_MOVE event), and
  3. Released the mouse button (a MOUSE_UP event)?

For example (imagine Stack Overflow is a Flash application):

Flash: Tracking mouse position after click-and-drag (down-and-move), even outside the stage/browser?

Within the app, I'm able to track the mouse X and Y positions with a MOUSE_MOVE event listener, but I lose it when it goes outside of the browser...

So, how do I track the position of the mouse no matter where it goes?

For a good example, try Google Finance. Try dragging the chart around; it'll still drag around if you move your mouse out of the browser window, and the mouse will be outside of the browser when you release it.

Also, check out KOKO KAKA; If you click on the scrollbar (make the browser window really small) and move outside of the browser window, the scroll bar moves just like a real one would.

I believe both only work because the MOUSE_DOWN event "captures" the mouse, allowing the Flash application to track the position of the mouse even when it is outside 开发者_如何学Cof the browser.

How would you be able to keep the event fired like this??

Thanks! ♥


This is possible using the MouseEvent.MOUSE_MOVE event. Put this code on the first frame of an fla with a Dynamic TextField that has an instance name of "output" on the stage.

import flash.events.MouseEvent;

stage.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDownHandler );
stage.addEventListener( MouseEvent.MOUSE_UP, onMouseUpHandler );

function onMouseDownHandler ( evt : MouseEvent ) : void
{
    outputText( "Mouse Down" );
    stage.addEventListener( MouseEvent.MOUSE_MOVE, onMouseMoveHandler );
}

function onMouseUpHandler ( evt : MouseEvent ) : void
{
    outputText( "Mouse Up" );
    stage.removeEventListener( MouseEvent.MOUSE_MOVE, onMouseMoveHandler );
}

function onMouseMoveHandler ( evt : MouseEvent ) : void
{
    outputText( "Mouse move" );
    outputText( "Mouse Y: " + mouseY );
    outputText( "Mouse X: " + mouseX );
}

function outputText ( outputString : String ) : void
{
    output.appendText( "\n" + outputString );
}

Click and drag the mouse off screen and you will see that move events are fired and you can get the x and y pos of the mouse. I tested this in a standalone swf and in the browser.


you can't - you can use the MOUSE_LEAVE listener to get when it leaves your flash area, but you can't get mouse position via JavaScript or Flash when your mouse is outside of the browser viewport (not even the toolbar, status bar, etc).

0

精彩评论

暂无评论...
验证码 换一张
取 消