Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Working with Movie Clips > Dragging movie clips | |||
You can use the global startDrag() function or the MovieClip.startDrag() method to make a movie clip draggable. For example, you can make a draggable movie clip for games, drag-and-drop functions, customizable interfaces, scroll bars, and sliders.
A movie clip remains draggable until explicitly stopped by stopDrag() or until another movie clip is targeted with startDrag(). Only one movie clip at a time can be dragged in a SWF file.
To create more complicated drag-and-drop behavior, you can evaluate the _droptarget property of the movie clip being dragged. For example, you might examine the _droptarget property to see if the movie clip was dragged onto a specific movie clip (such as a "trash can" movie clip) and then trigger another action, as shown in the following example:
// Drag a piece of garbage.
garbage_mc.onPress = function() {
this.startDrag(false);
};
// When the garbage is dragged over the trashcan, make it invisible.
garbage_mc.onRelease = function() {
this.stopDrag();
// Convert the slash notation to dot notation using eval.
if (eval(this._droptarget) == trashcan_mc) {
garbage_mc._visible = false;
}
};
For more information, see startDrag function or startDrag (MovieClip.startDrag method) in the ActionScript 2.0 Language Reference.
For a sample source file, gallery_tween.fla, that provides an example of how to use ActionScript to control movie clips dynamically while loading image files into a SWF file, which includes making each movie clip draggable, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download and decompress the Samples zip file and navigate to the ActionScript2.0/Galleries folder to access the sample.
|
|
|
|