startDrag() and stopDrag()
Only movieclip symbols can be set to be draggable.You need to use dot syntax to specify the name of the instance that will have this method applied to it.
movie_mc •startDrag();
Only movieclip symbols can be set to be draggable.You need to use dot syntax to specify the name of the instance that will have this method applied to it.
movie_mc •startDrag();
If you have an instance of a movieclip called doll_mc, and you want it to become dragable when the user holds the mouse button and mean while it holds it, and stop when he releases the mouse, you will have to create eventhandlers for this conditions, tp define when exactly the movieclip will be draggable.
doll_mc. addEventListener (MouseEvent.MOUSE_UP, stopdragthing)
doll_mc. addEventListener (MouseEvent.MOUSE_DOWN, startdragthing)
function stopdragthing (e:MouseEvent):void {
doll_mc.startDrag(); }
function startdragthing (e:MouseEvent):void {
doll_mc.stopDrag();
}
For a group of elements, a more object oreinted code:
red_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
red_mc.addEventListener(MouseEvent.MOUSE_UP, drop);
green_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
green_mc.addEventListener(MouseEvent.MOUSE_UP, drop);
blue_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
blue_mc.addEventListener(MouseEvent.MOUSE_UP, drop);
function drag(event:MouseEvent):void {
event.target.startDrag();
}
function drop(event:MouseEvent):void {
event.target.stopDrag();
}
http://www.riacodes.com/flash/draggable-area-with-as3/
area_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragArea);
area_mc.addEventListener(MouseEvent.MOUSE_UP, dropArea);
function dragArea(e:MouseEvent):void{
var bounds:Rectangle = new Rectangle(
stage.stageWidth - area_mc.width,
stage.stageHeight - area_mc.height,
area_mc.width - stage.stageWidth,
stage.stageHeight - area_mc.height,
area_mc.width - stage.stageWidth,
area_mc.height - stage.stageHeight
);
area_mc.startDrag(false, bounds);
}