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

Drag and Drop movie clip

Problem
Need drag and drop movie clip + separate code from .fla file to .as file.

Solution
Using startDrag/stopDrag, and addEventListener/removeEventListener.

Detailed explanation

package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class DragDrop extends MovieClip {
function DragDrop() {
trace("class DragDrop working");
this.addEventListener(MouseEvent.MOUSE_DOWN,
dragFlower);
this.buttonMode=true;
}
function dragFlower(event:MouseEvent):void {
trace("starting dragFlower working");
this.startDrag();
this.addEventListener(MouseEvent.MOUSE_UP, dropFlower);

}
function dropFlower(event:MouseEvent):void {
trace("dropFlower working too");
this.stopDrag();
this.removeEventListener(MouseEvent.MOUSE_UP,
dropFlower);
}
}
}

index18

index24

Source:
drag_and_drop_movie_clip

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>