February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

Putting a movie clip to original position after drop

Problem
You need to organize a drag and drop effect. And when the user drops the movie clip on the stage, the movie clip must appear in the original position (when the user drags this movie clip.)

Solution
Tracking movie clip coordinates. To do this we need to create 2 variables originalPositionX and originalPositionY. Also we will use the existing coordinates of movie clip, and for this we will use this.x and this.y.

Detailed explanation

package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class DragDrop extends MovieClip {
var originalPositionX:Number;
var originalPositionY:Number;

public function DragDrop() {
trace("class DragDrop working");
this.addEventListener(MouseEvent.MOUSE_DOWN,
dragFlower);
this.buttonMode=true;
}
private function dragFlower(event:MouseEvent):void {
trace("starting dragFlower working");
this.startDrag();
this.addEventListener(MouseEvent.MOUSE_UP, dropFlower);
originalPositionX=this.x;
originalPositionY=this.y;
}
private function dropFlower(event:MouseEvent):void {
trace("dropFlower working too");
this.stopDrag();
this.removeEventListener(MouseEvent.MOUSE_UP,
dropFlower);
this.x=originalPositionX;
this.y=originalPositionY;
}
}
}

pink_flower_64x64

Source:
put_movie_clip_to_original_position_after_drop

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>