flash animation video tutorials

 

 

 

START LEARNING
FLASH NOW

Get instant access to over
45 minutes of FREE Flash tutorials on video
 and our newsletter.

Name:
E-Mail:
Phone:
Describe

.

.

.

 
Web video-animation.com

.

.

flash tutorials flash tutorials flash tutorials flash tutorials

Flash 8 Drag And Drop

This tutorial is the Flash 8 update to the Flash MX version that I have done on drag and drop. No code goes on any of the movieclips but all code is put in the one place, that is, the actions frame. In the past I have put code all over the place but the best way to do it is to keep it all together in the one place. It is much easier to debug and control and you do not get hopelessly lost.

Flash Tutorials in Video Format - Watch them now at LearnFlash.com  

So let us commence. Create a new flash file.
Rename the default layer to "draggers". On frame 1 create a movieclip, and call it drag1_mc.
In the properties window, give it the instance name of drag1_mc.
Create another MovieClip on the same layer, and call it drag2_mc, and of course give it the instance name of drag2_mc.
Lock the layer "draggers", and create a new layer underneath that one and call it "droppers".

On the droppers layer, create a new MovieClip and call it drop1_mc. This is the drop zone for the first dragger MovieClip.
Give it the instance name of drop1_mc.
Create another MovieClip on the droppers layer and call it drop2_mc. Give it the instance name of drop2_mc.
Lock the droppers layer.

Create a new layer and call it actions and lock it.
Select frame 1, actions layer and open the Actions Window(F9). And put this code in the window.

stop();
// start points
// these are the original starting points for the draggers
// this is where they snap back to if wrong.
var start1x:Number = drag1_mc._x;
var start1y:Number = drag1_mc._y;
var start2x:Number = drag2_mc._x;
var start2y:Number = drag2_mc._y;
// allow the movieclips to be dragged by mouse
// start drags…
drag1_mc.onPress = function() {
startDrag(this);
};
drag2_mc.onPress = function() {
startDrag(this);
};
//
// drop them..
// drag 1 gets dropped on drop1 
// else goes back to start position
drag1_mc.onRelease = function() {
	// stop dragging
this.stopDrag();
// if correct drop zone
if (eval(this._droptarget) == drop1_mc) {
	// leave it there
this._x = drop1_mc._x;
this._y = drop1_mc._y;
} else {
	// take back to start pos
this._x = start1x;
this._y = start1y;
}
};
//drag 2 
drag2_mc.onRelease = function() {
this.stopDrag();
if (eval(this._droptarget) == drop2_mc) {
this._x = drop2_mc._x;
this._y = drop2_mc._y;
} else {
this._x = start2x;
this._y = start2y;
}
};

Remember:
Do not forget to give MovieClips and Buttons instance names. It is probably the most common error of the century. If it does not work, check your instance names because that is most likely where the error is.

Make sure that your draggers layer is above your droppers layer. Otherwise it will go underneath and you will not be able to see them.

Flash 8 Resources

Flash 8 Drag and drop code With centering
Flash MX drag and drop tutorial
Another drag and drop tutorial
Flash Drag and drop forum

.

flash 8