Creating drag and drop functionality in Flash CS3 is quite different than in older versions if you’re using the new ActionScript 3.0. While still relatively straightforward, the code can be a little more intimidating to users who are less familiar with ActionScript programming. If you’re like me, you’re here to try to keep your knowledge up-to-date, so let’s learn how to create a simple ActionScript 3.0 drag and drop game step-by-step. Download the FLA and follow along with these steps.
Description
The dd_tile_list class extends the as3 TileList component to add drag and drop functionality. Dropping between components is supported. This class aims to be CellRenderer and Style agnostic.
The swapDepth is not available on AS3, rather much more simplest way is available.
The below commented code can be achieved through the single line: event.target.parent.addChild(event.target);
I used to teach drag-n-drop funtionality using startDrag() and stopDrag() MovieClip methods. This is the easiest and fastest way but it tends to be choppy when the framerate is low. To solve this problem, you should employ MOUSE_MOVE event as shown in this tutorial by Flash and Math.
Their tutorial is great and I’ll use their concept in this article. But I don’t want the draggable object to snap to its center when dragging. I’ll put in a lockcenter option and a swapDepths() alternative.
Notes:
The drag-and-drop interface is particularly valuable for educational purposes. Since much of the standard documentation on Flash CS 3 and Actionscript 3 is focused (at least initially) on animation and multimedia applications, we felt it would be useful to provide some tutorial pages on using the drag and drop interface written for those who have only a rudimentary understanding of Adobe Flash. If you have never written a line of code in Flash before, we recommend you start with one of the earlier Basic tutorials on this site such as Simple Line Segment: Creating Sprites and Shapes from Mouse Clicks.
This example belongs to the AS3 Tutorials Novice and is part of our Actionscript 3 tutorial series.
You will learn how to implement simple drag and drop applications.
Dragging and dropping objects is a popular brick in edutainment programs. This is part of Flash CS3 tutorials. It is probably not suitable for Flash designers without any programming experience.
This tutorial is all about dragging an object around the stage. You will learn different ways to implement dragging. I’ll also show you how to add some animation with the dragging. So start your Flash IDE and let’s get going!
In ActionScript 3.0, buttons and interactive movieclip stuff is scripted differently. To understand in depth about how ActionScript 3.0 works for interactivity see the diagram beside.
Diagram besides show, a pin with a tag attached to it. In Action Script 3.0, all events such as mouse clicks, mouse move, mouse over, keyboard inputs, even movieclip’s frame movement is controlled using event listeners. You can attached this event listeners to any movieClip, components, stage or sprites to add interactivity features to it. Just like how the pin works…just attach the pin to the object.
Each event listeners has a trigger function. Trigger function is a script which triggers because of the specific event for example, a mouse click. This means if you attached an event listener for mouse click on a button, the trigger function itself will be the script for the button. This is how you make button scripts in Action Script 3.0. Similar to our old on(Press) function.
来自:http://www.lemlinh.com/flash-tutorials-as3-drag-and-drop/