PDA

View Full Version : drag with easing



rlLife
November 11th, 2004, 12:13 PM
i have this script that i am using to drag with easing. it works but how do i make sure it stops when it gets to the edge of the movie. Right now since there is easing on it, you can throw the shape right off of the stage. Is there a way it can stop?

rL

this code on the MC:

onClipEvent (load) {
xfinal = _x;
yfinal = _y;
}
onClipEvent (enterFrame) {
if (drag) {
x = _root._xmouse+xd;
y = _root._ymouse+yd;
} else {
x = xfinal+xd;
y = yfinal+yd;
}
_x = _x+(x-_x)/1.3;
_y = _y+(y-_y)/1.3;
}

this code on the button inside of MC:

on (press) {
drag = true;
xd = _x-_root._xmouse;
yd = _y-_root._ymouse;
Mouse.show();
}
on (release, releaseOutside) {
drag = false;
xfinal = _root._xmouse;
yfinal = _root._ymouse;
Mouse.show();
}

icio
November 11th, 2004, 12:22 PM
just add this to the enterFrame:

if (this._x < minX) {
this._x = minX;
} else if (this._x > maxX) {
this._x = maxX;
}
if (this._y < minY) {
this._y = minY;
} else if (this._y > maxY) {
this._y = maxY);
}
//minX, maxX, minY, maxY should be replaced with the values of the maxinmum/minimum values for x/y that would would like.

hope this helps :thumb:

caiosartori
May 15th, 2010, 12:15 PM
just add this to the enterFrame:

if (this._x < minX) {
this._x = minX;
} else if (this._x > maxX) {
this._x = maxX;
}
if (this._y < minY) {
this._y = minY;
} else if (this._y > maxY) {
this._y = maxY);
}
//minX, maxX, minY, maxY should be replaced with the values of the maxinmum/minimum values for x/y that would would like.

hope this helps :thumb:


Dont work, how to change this code for to work?