I have a red square that I want to drag only on the x-axis. I've worked out a simple script, which theoretically should work, but it's not behaving properly. It's a bit hard to explain..the square keeps starting at the wrong position and the stage position seems to be changing so sometimes you can't drag the square all the way to the right...
red.buttonMode = true;
red.addEventListener(MouseEvent.MOUSE_DOWN, dragHandler);
function dragHandler(e:MouseEvent):void {
var ypos:Number = e.currentTarget.y;
var xpos:Number = e.currentTarget.x;
e.currentTarget.startDrag(false,new Rectangle(-xpos,ypos,stage.stageWidth,0));
}
red.addEventListener(MouseEvent.MOUSE_UP, dropHandler);
function dropHandler(e:MouseEvent) {
//trace("red up");
e.currentTarget.stopDrag();
}