Return to Kroll Web Design home page Flash tutorials

« Return

ActionScript 3

Dragging using the startDrag and stopDrag methods

This example uses the built-in Flash methods of startDrag and stopDrag to allow you to move the walking man around the confines of the Flash movie by dragging with your mouse.

Download the FLA file



var walker_mc:Walker = new Walker();

walker_mc.x = 200;
walker_mc.y = 200;
walker_mc.scaleX = .5;
walker_mc.scaleY = .5;
walker_mc.buttonMode = true;

addChild(walker_mc);

walker_mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownFunction);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpFunction);

function mouseDownFunction(myEvent:MouseEvent):void
{
	walker_mc.startDrag();
}

function mouseUpFunction(myEvent:MouseEvent):void
{
	walker_mc.stopDrag();
}