Question

i just wanted to know if it is possible to check in mouse event whether the object is grabbed or not in Action Script.

For example: youtube video player is also built in flash. and when we grab the track, it just stays with the mouse pointor and when we release it. it stops wherever we left it.

Was it helpful?

Solution

// define lock on y-axis
var LOCKY:Number = target.y;

// MouseEvent.MOUSE_MOVE
stage.addEventListener(MouseEvent.MOUSE_MOVE, _mouseMove);
function _mouseMove(e:MouseEvent):void
{
    if(target.y != LOCKY) target.y = LOCKY;
}

// dragging
target.addEventListener(MouseEvent.MOUSE_DOWN, _mouseDown);
function _mouseDown(e:MouseEvent):void
{
    target.startDrag();
    target.addEventListener(MouseEvent.MOUSE_UP, _mouseUp);
}

// dropping
function _mouseUp(e:MouseEvent):void
{
    target.stopDrag();
    target.removeEventListener(MouseEvent.MOUSE_UP, _mouseUp);
}

Taken directly from here: AS3 How to startdrag only on x-axis?

OTHER TIPS

There is no way to determine if an object is being dragged after startDrag() has been called on it. You would have to set a boolean that tracks when you started the drag.

Personally I do not like startDrag/stopDrag and so I don't use it. But if you are starting out then startDrag/stopDrag can work. I would guess that youtube's player doesn't not use the feature. I will post my method here at a later time when I have access to it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top