Drag and Drop

In the movie below you can drag and drop the star.

Get Adobe Flash player

The instance on the stage is named star. We need two event listeners to complete the drag and drop cycle. On mouse down we start to drag and on mouse up we stop dragging, or drop. The code is shown below:

star.addEventListener(MouseEvent.MOUSE_DOWN, clickToDrag);
star.addEventListener(MouseEvent.MOUSE_UP, releaseToDrop);

function clickToDrag(e:MouseEvent):void {
  star.startDrag();
}

function releaseToDrop(e:MouseEvent):void {
  star.stopDrag();
}

Download the movie

NEXT: e.target: Using the same code for many shapes