-1

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.

2 Answers2

0
// 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?

Community
  • 1
  • 1
loxxy
  • 12,990
  • 2
  • 25
  • 56
  • It could be any object or movieclip that is to be dragged. – loxxy Mar 25 '12 at 14:51
  • voted down for: 1) MouseEvent.MOUSE_MOVE handler is active all the time 2) MouseEvent.MOUSE_UP is added to target rather then stage – average dev Mar 25 '12 at 15:53
  • @Pavel This is not my answer, If you look at the comments I have simply copied the link contents which has helped the OP. Either ways, you don't vote down people for bad programming practices. – loxxy Mar 25 '12 at 17:47
  • @loxxy it is not a "bad practice", it is not really a working solution if you really take a look at the code. Regarding solution — it doesn't answer the question, which on it's own turn is pretty basic, which means author haven't searched for answer AT ALL. The correct answer was made by grapefrukt in the comments. – average dev Mar 25 '12 at 21:01
0

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.

ktamlyn
  • 4,519
  • 2
  • 30
  • 41