|
||||||||||||||||
. . . . . |
Flash 8 Drag And DropThis 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.
On the droppers layer, create a new MovieClip and call it drop1_mc. This is the drop zone for the first dragger MovieClip.
Create a new layer and call it actions and lock it.
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: Flash 8 Resources
Flash 8 Drag and drop code With centering . |
|
||||||||||||||
|
. | Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Forum | Games | free backgrounds | Resume | Flash Animations | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | store | advertisers | . . |
||||||||||||||||