Drag and drop code
reset.addEventListener(MouseEvent.CLICK, comeHome);
function comeHome(e:Event) {
mc.x = 115;
mc.y = 70;
}
function initDragger(mc:MovieClip):void
{
mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownDragger);
mc.addEventListener(MouseEvent.MOUSE_UP, mouseUpDragger);
}
function mouseDownDragger(e:MouseEvent):void
{
e.currentTarget.startDrag();
}
function mouseUpDragger(e:MouseEvent):void
{
e.currentTarget.stopDrag();
}
// Set up drag
initDragger(mc);
startDrag()
Lets the user drag the specified sprite. The sprite remains draggable until explicitly stopped through a call to the Sprite.stopDrag() method, or until another sprite is made draggable. Only one sprite is draggable at a time. Three-dimensional display objects follow the pointer and Sprite.startDrag() moves the object within the three-dimensional plane defined by the display object. Or, if the display object is a two-dimensional object and the child of a three-dimensional object, the two-dimensional object moves within the three dimensional plane defined by the three-dimensional parent object.
Parameters
lockCenter:Boolean (default = false
) — Specifies whether the draggable sprite is locked to the center of the pointer position (
true
), or locked to the point where the user first clicked the
sprite (false
).
bounds:Rectangle(default = null
) — Value relative to the coordinates of the Sprite's parent that specify a constraint
rectangle for the Sprite.
stopDrag()
Ends the startDrag() method. A sprite that was made draggable with the startDrag() method remains draggable until a stopDrag() method is added, or until another sprite becomes draggable. Only one sprite is draggable at a time.
No comments:
Post a Comment