Either do something like this:
mySprite.addEventListener("mouseDown", mouseDownHandler);
stage.addEventListener("mouseUp", mouseUpHandler);
protected function mouseDownHandler (e:MouseEvent):void{
e.target.startDrag();
}
protected function mouseDownHandler (e:MouseEvent):void{
e.target.stopDrag();
}
You can pass 2 arguments to the startDrag method, the first is a boolean to lock to center, the second is a Rectangle-object for boundary-points.
And for a more controlled behavior you can do something like this instead:
mySprite.addEventListener("mouseDown",
mouseDownHandler);
stage.addEventListener("mouseUp", mouseUpHandler);
protected function mouseDownHandler (e:MouseEvent):void{
stage.addEventListener("mouseMove",
mouseMoveHandler);
}
protected function mouseDownHandler (e:MouseEvent):void{
stage.removeEventListener("mouseMove",
mouseMoveHandler);
}
protected function mouseMovehandler(e:MouseEvent):void{
mySprite.x=mouseX;
mySprite.y=mouseY;
}
(haven't tested the code so there might be some small syntax-error or something)