Dragging movie clips 125
Changing movie clip position and appearance
To change the properties of a movie clip as it plays, write a statement that assigns a value to a
property or use the
setProperty() function. For example, the following code sets the rotation of
instance
mc to 45:
mc._rotation = 45;
This is equivalent to the following code, which uses the setProperty() function:
setProperty("mc", _rotation, 45);
Some properties, called read-only properties, have values that you can read but not set. (These
properties are specified as read-only in their ActionScript Dictionary entries.) The following are
read-only properties:
_currentframe, _droptarget, _framesloaded, _parent, _target,
_totalframes, _url, _xmouse, and _ymouse.
You can write statements to set any property that is not read-only. The following statement sets
the
_alpha property of the movie clip instance wheel, which is a child of the car instance:
car.wheel._alpha = 50;
In addition, you can write statements that get the value of a movie clip property. For example, the
following statement gets the value of the
_xmouse property on the current level’s Timeline and
sets the
_x property of the customCursor instance to that value:
onClipEvent(enterFrame){
customCursor._x = _root._xmouse;
}
This is equivalent to the following code, which uses the getProperty() function:
onClipEvent(enterFrame){
customCursor._x = getProperty(_root, _xmouse);
}
The _x, _y, _rotation, _xscale, _yscale, _height, _width, _alpha, and _visible properties
are affected by transformations on the movie clip’s parent, and transform the movie clip and any
of the clip’s children. The
_focusrect, _highquality, _quality, and _soundbuftime
properties are global; they belong only to the level 0 main Timeline. All other properties belong to
each movie clip or loaded level.
For a list of movie clip properties, see “Property summary for the MovieClip class” on page 484.
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 can be dragged at a time.
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 to a specific movie clip (such as a “trash can” movie clip) and
then trigger another action. For detailed information, see
startDrag() on page 645 or
MovieClip.startDrag() on page 534.