Professional Documents
Culture Documents
Create A Drag and Drop Puzzle in Action Script 3
Create A Drag and Drop Puzzle in Action Script 3
0
Carlos Yanez on Jan 11th 2010 with 26 comments Share Drag-and-drop is the action of clicking on a virtual object and dragging it to a different location or onto another virtual object. In general, it can be used to invoke many kinds of actions, or create various types of associations between two objects. In this tutorial we will create a Drag and Drop Matching game using ActionScript 3.
Step 2: Starting
Open Flash and create a new Flash File (ActionScript 3).
Set the stage size to 450300 and add a black background (#1B1B1B).
Convert the rectangle to MovieClip and duplicate it (Cmd + D) to match the number of draggable objects. The instance names will be the name of the draggable clip, plus Target, leaving us with denTarget, oceanTarget, etc.
Step 5: Guides
Lets add some guides to help the user figure out what to do. A title that will tell the user what to do with the elements in the screen.
4.
import flash.events.MouseEvent;
Step 9: Variables
These are the variables we will use, explained in the comments. view plaincopy to clipboardprint? 1. var xPos:int; //Stores the initial x position 2. var yPos:int; //Stores the initial y position
5. }
1. private function addListeners(... objects):void 2. { 3. for (var i:int = 0; i < objects.length; i++) 4. { 5. objects[i].addEventListener(MouseEvent.MOUSE_DOWN, dragObject); 6. objects[i].addEventListener(MouseEvent.MOUSE_UP, stopDragObject); 7. } 8. }
Conclusion
Now you know how to easily make a drag target, this can be very useful for games and applications. Make your own drag app and take this concept further! Thanks for reading!