Mouse Dragging MovieClip with Flash ActionScript 3
With Flash ActionScript 3, this is quite easy to use mouse dragging objects around on the stage.
Flash Tutorial Content:
Many Flash application and games require using mouse to drag some objects on the stage. With Flash ActionScript 3, this is quite easy to accomplish this effect.
The complete Flash Movie is shown as above, you may try how it works before you start this tutorial.
Flash ActionScript Codes:
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseStartDrag);
function mouseStartDrag(motion:MouseEvent):void {
square_mc.startDrag();
// Dispaly message
output_txt.text = "Dragging Square now....";
}
stage.addEventListener(MouseEvent.MOUSE_UP, mouseStopDrag);
function mouseStopDrag(motion:MouseEvent):void {
square_mc.stopDrag();
// Display message
output_txt.text = "Square was dragged to: " + "(" + square_mc.x + ", " + square_mc.y + ")";
Download Flash Source File:
Remarks:
This Flash ActionScript tutorial shows how to drag objects or movieclip on stage.