[MX04] Drag and Drop- locking object into center of target...
Hello all,
New member and relatively new Flash user. I created a drag and drop in Flash MX 2004, and I'm trying to find script that will lock the object into the center of the target when it is dragged over, sort of like a magnet effect. Here is the script I currently have on each object:
Hi
Maybe this example found on flashkit will help you:
code:
// dragMe_mc is the instanceName of the movieClip
// Starts the drag onPress
dragMe_mc.onPress = function() {
this.origX = this._x;
this.origY = this._y;
this.startDrag();
};
dragMe_mc.onRelease = function() {
// stops drag onRelease
this.stopDrag();
// dymainc txtField+Message displays "error"
if (dropHere_mc.hitTest("_root.dragMe_mc")) {
// snaps the dragMe_mc to the dropHere_mc in the middle of _x&_y
this._x = _root.dropHere_mc._x;
this._y = _root.dropHere_mc._y;
// dynamic txtField+message displays "success"
infoText = "Congratulations you dropped it correctly";
// disables this dragMe_mc from being dragged again after dropped correctly
this.enabled = false;
} else {
infoText = "You dropped it incorrectly";
this.onEnterFrame = function() {
//temporary values here to hold the x & y distance because
// they're being referenced more than once
var dx = this.origX-this._x;
var dy = this.origY-this._y;
//approximation of the distance to the original position
if (Math.max(dx, dy)<.1) {
// stop moving when we're close enough
this.onEnterFrame = undefined;
}
this._x += dx/3;
// 3 controls the speed - use a larger number for slower movement
this._y += dy/3;
};
}
};
im kind of in a hurry so i cant explain it all but i know when you use the function
startDrag();
you can give it the parameter
lockcenter
like this
startDrag(lockcenter);
if you want more parameters when you type
startDrag(
flash should give you a list of example parameters