MovieClip._droptarget Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
MovieClip._droptarget Property Flash 4

the path to the clip or movie on which a dragged clip was dropped read-only
mc._droptarget

Description

If mc is being dragged, _droptarget returns a string indicating the path to the clip over which mc hovers (if any). If mc is not hovering over a clip, _droptarget returns undefined. If mc was previously dragged and then dropped on a clip, _droptarget returns 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. If mc hovers over two or more overlapping clips, only the topmost clip is considered the _droptarget. To detect intersection between any number of overlapping clips, use MovieClip.hitTest( ).

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 the item_mc clip is dropped onto the basket clip, it is allowed to stay in the basket; otherwise, the item_mc is returned to its original location:

// Set original location item_mc.origX = _x; item_mc.origY = _y;     // Define a function to call when the item is clicked item_mc.drag = function () {   this.startDrag(); }     // Define a function to call when the item is dropped item_mc.drop = function () {   stopDrag();   if (this._droptarget != "/basket") {     this._x = this.origX;     this._y = this.origY;   } }     // Assign our drag/drop callback to the appropriate item_mc button handlers item_mc.onPress = item_mc.drag; item_mc.onRelease = item_mc.onReleaseOutside = item_mc.drop;

Note that _droptarget stores a string in slash notation, not as a clip reference. To convert a _droptarget string to a movie clip reference, use the technique shown in the Example under the eval( ) global function.

See Also

MovieClip.startDrag( ), MovieClip.stopDrag( )



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net