Tutorials with samples for drag and drop in Flash AS3
Hi Friends,
Hi Friends,
Hello Jones,
I will suggest that you must view and understand this tutorial from https://code.tutsplus.com/tutorials/create-a-drag-and-drop-puzzle-in-actionscript-30–active-2920. It is a simple drag and drop game done in actionscript 3.0.
It this tutorial you’ll learn how to make a draggable movie clip and dropped it off onto your desired position, and the hitTestObject method which is a function in actionscript 3.0.
They are also providing source code and demo, so you’ll not start from scratch.
Happy learning!
Hello Jones,
This Flash tutorial will teach you about the basic drag and drop in Actionscript 3.0. You will learn how to drag an object around the stage. I have used an image of a sheep as the object to demonstrate the drag and drop functionality.
Step 1. Create the object.
Open a new Flash document and create whatever object you wish. Alternatively you could use an image as an object, like I have, by selecting File > Import > Import to stage select your file and click ok.
Step 2. Convert object to symbol.
Step 3. Add the code.
On the timeline insert a new layer called “actions” right click on the first frame and select Actions from the drop down menu.
Add the following code:
sheep_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag); sheep_mc.addEventListener(MouseEvent.MOUSE_UP, drop); function drag(event:MouseEvent):void { sheep_mc.startDrag(); } function drop(event:MouseEvent):void { sheep_mc.stopDrag(); }
**The first and second lines of code add event listeners for the mouse up and mouse down events with the parameters drag and drop.
The drag function starts the dragging of the object when the mouse is pressed, and the drop function stops the dragging of the object when the mouse is released.
Step 4. Test your movie.
Test your movie Ctrl + Enter. Now use your mouse to drag and drop the sheep.