Name

MovieClip._droptarget Property — the path to the clip or movie on which a dragged clip was dropped

Availability

Flash 4 and later

Synopsis

mc._droptarget

Access

Read-only

Description

If mc is being dragged, _droptarget stores a string indicating the path to the clip over which mc hovers (if any). If mc is not hovering over a clip, _droptarget stores undefined. If mc was previously dragged and then dropped on a clip, _droptarget stores a string indicating the path to the clip upon which mc was dropped. The path is provided in slash notation. A movie clip is considered to be “over” another clip if the registration point of the dragged clip overlaps any portion of the target clip.

Example

The _droptarget property is convenient for creating drag-and-drop interfaces. The following example demonstrates how to create a simple shopping-basket interface using _droptarget (when an item clip is dropped onto the basket clip, the item is allowed to stay in the basket; otherwise, the item is returned to its original location):

                     
// CODE ON FRAME ONE OF item
var origX = _x;
var origY = _y;

function drag( ) {
  this.startDrag( );
}

function drop( ) {
  stopDrag( );
  if (_droptarget != "/basket") {
    _x = origX;
    _y = origY;
  }
}

// CODE ON A BUTTON IN item
on (press) {
  drag( );
}

on (release) {
  drop( );
}

Note that _droptarget stores a string, not a clip reference. To convert a _droptarget string to a movie clip reference, use the technique shown in the example for eval( ).

See Also

MovieClip.startDrag( ), MovieClip.stopDrag( ...

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.