Start drag Method using the AS3
4.6.2009, 13:15 Total views: 5824
Using this thoroughly explained, detailed action script 3 flash lesson, you will see how to drag any object using the mouse cursor. The startDrag method accepts a number of optional parameters which allow you to constrain the drag, that is to box it in to specified dimensions and it’s really easy to create. In this lesson, we’re using a Movie Clip symbol, because the MovieClip class supports startDrag() and stopDrag() methods. Using this lesson, you will also learn how to import any image into a flash stage, how to convert it into a Movie Clip Symbol, how to create instance name and much much more!
Example:
Step 1
Press Ctrl+J key on the keyboard (Document Properties) and set the dimensions of your doucment as whatever you like. Select any color as background color. Set your Flash movie's frame rate to 45 and click ok.
Step 2
Using the flash Tools for drawing, draw any object which you like to use for this lesson.
Step 3
While the object is still selected, hit F8 key (Convert to Symbol) to convert it into a Movie Clip Symbol.

Step 4
While the new made Movie Clip (object) is still selected, go to the Properties Panel below the stage. On the left side, You will find the Instance name input field there. Call this Movie Clip object_mc. See the picture below!

Step 5
It's time for action script code. This code goes in a keyframe where that movie clip starts. So, select the first frame and go to the AS panel (F9). Then, enter this code inside the actions panel:
object_mc.buttonMode = true; object_mc.addEventListener ( MouseEvent.MOUSE_DOWN, function(evt:MouseEvent):void { object_mc.startDrag (); } ); object_mc.addEventListener ( MouseEvent.MOUSE_UP, function(evt:MouseEvent):void { object_mc.stopDrag (); } );
We're done now!
Test your Movie and enjoy!
Download source file (.fla)
|
 |
|
|
|
Related links
|
 |
|