1. create a new FLA
2. Create a basic 50x50 red circle (fig1). Press F8, name the symbol redCircleMC and convert it as a movie clip (fig2). Be sure to set the registration point at the center (fig3), you will understand why you need to do that later on. In the panel properties, give it the Instance name redCircle (fig4).
fig1
fig2
fig4 Now let's assign a bit of code to that movie clip to be able to drag and drop it anywhere on the stage.
3. on the first frame of the main timeline enter the following code :
redCircle.onPress = function(){ |
When the mouse is released (onRelease action) the drag ends.
let's have a quick look at the startDrag parameters :
This is what the Flash 8 manual tells us about the startDrag method :
| startDrag function startDrag(target:Object, [lock:Boolean, left:Number, top:Number, right:Number, bottom:Number]) Makes the target movie clip draggable while the movie plays. Only one movie clip can be dragged at a time. After a startDrag() operation is executed, the movie clip remains draggable until it is explicitly stopped by stopDrag() or until a startDrag() action for another movie clip is called. Parameterstarget:Object - The target path of the movie clip to drag. lock:Boolean [optional] - A Boolean value specifying whether the draggable movie clip is locked to the center of the mouse position (true ) or locked to the point where the user first clicked the movie clip (false ). left,top,right,bottom:Number [optional] - Values relative to the coordinates of the movie clip's parent that specify a constraint rectangle for the movie clip. |
The first parameter target is easy to understand, it represents the movie clip that you want to drag. In our code above we use the keyword this to refer to the movie clip redCircle but we might as well replace this by redCircle it would do the job as well in our case. In any case the first parameter target need to refer to the Movie clip that you want to drag.
Continue to next page...