Dragging movie clips
359
■
On the Macintosh, browse to
Macintosh HD
/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Galleries.
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
.
You can a sample photo gallery application on your hard disk.This file 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. You can find the sample source
file, gallery_tween.fla, in the Samples folder on your hard disk.
■
In Windows, browse to
boot drive
\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Galleries.
■
On the Macintosh, browse to
Macintosh HD
/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Galleries.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...