PDA

View Full Version : AS Movement to X,Y



sixfortyfive
June 27th, 2005, 05:39 PM
What is a good function to simply move an object to X and Y coordinates?

I've looked around the forums, and all I can find is actionscript that does movement plus other animations, like rotate and scale.

I just want to let the user drag an object, but when they release it, that object moves back to certain X and Y coordiantes.

lunatic
June 27th, 2005, 05:54 PM
Voetsjoeba's golden formula :love:



MovieClip.prototype.ease = function(x,y){
this.onEnterFrame = function(){
this._x = x-(x-this._x)/1.1;
this._y = y-(y-this._y)/1.1
if(this._x > x-1 && this._x < x+1 && this._y > y-1 && this._y < y+1){
this._x = x;
this._y = y;
delete this.onEnterFrame
//do other stuff here, this is the point at which the object reaches its target
}
}
}
MC.ease(100,100);


Where 100, 100 is the x, y coordinates to move to. Put that last bit inside the on(release) of the object being dragged.

:hr: