AS3: Simple Drag and Drop in Flash

Drag and Drop is when you are able to move something with the mouse on screen. It is commonly use to create learning activities where elements needs to be associated. You can also find lots of games that use this method.

Step 1: Create a new Flash movie with the ActionScript version set to 3.0. The background color, frame rate and the stage size do not matter for this tutorial.

Step 2: Create one new layer, so you will have two layers.

Step 3: Now, select layer 1. Pick the Oval Tool (O), set the Stroke Color to black and the Fill Color to something light. Draw a circle on the stage.

Step 4: Use the Select Tool (V) and select the circle. Now Press F8 on your keyword to convert it to a symbol.  The symbol Type should be: Movie Clip.

 

Step 5: Select the circle, access the Properties Inspector and set circle_mc as the instance name. We need the instance name to be able to refer to our bar through ActionScript.

Step 6: click once on the name of the Actions layer and then right-click the only frame on it and select Actions to open Actions panel.

Step 7: Copy and paste this code to your Actions panel.

 circle_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
circle_mc.addEventListener(MouseEvent.MOUSE_UP, drop);
function drag(event:MouseEvent):void {
 circle_mc.startDrag();
}
function drop(event:MouseEvent):void {
 circle_mc.stopDrag();
}

That’s it, We are done :) ! Go through Control>Test Movie and see how your simple Drag and Drop works!

Downloads:

Flash CS3: Simple Drag and Drop in Flash

Flash CS4: Simple Drag and Drop in Flash

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Twitter
  • Twitthis
            Delicious     Bookmark this on Delicious

Copyright & Usage

The effects and techniques demonstrated in tutorials on AllTutz can be used in whatever manner you wish without attribution. You cannot copy whole tutorials (unless permission is given), either in English or translated to another language.

Leave a Reply