If anyone is interested, I expanded a bit on Voetsjoeba’s code in order to add a “round” attribute, and a “speed” attribute. This is very useful when you need to ease a movieclip that uses Pixel fonts, or fonts that look best on whole pixels. Here are the two functions:
MovieClip.prototype.easeX = function(to,speed,round){
this.onEnterFrame = function(){
if(round!=true){
this._x += (to - this._x)/speed;
} else {
this._x += Math.round((to - this._x)/speed);
}
if(this._x > to-1 && this._x < to+1){
this._x = to;
delete this.onEnterFrame
//do other stuff here, this is the point at which the object reaches its target
}
}
}
MovieClip.prototype.easeY = function(to,speed,round){
this.onEnterFrame = function(){
if(round!=true){
this._y += (to - this._y)/speed;
} else {
this._y += Math.round((to - this._y)/speed);
}
if(this._y > to-1 && this._y < to+1){
this._y = to;
delete this.onEnterFrame
//do other stuff here, this is the point at which the object reaches its target
}
}
}
Usage Examples:
[size=1]mc.easeX(mc._x-100,5,true); // Move mc 100 pixels left, on solid pixels, at “5” speed[/size]
[size=1]mc.easeX(mc._x+100,10,false); // Move mc 100 pixels right, smoothly, at “10” speed[/size]
[size=1]mc.easeY(mc._y-100,5,true); // Move mc 100 pixels up, on solid pixels, at “5” speed[/size]
[size=1]mc.easeY(mc._y+100,10,false); // Move mc 100 pixels down, smoothly, at “10” speed[/size]
[size=1]mc.easeX(100,5,true); // Move mc to an X of 100, on solid pixels, at “5” speed[/size]
[size=1]mc.easeY(100,5,true); // Move mc to a Y of 100, on solid pixels, at “5” speed[/size]
[size=1]mc.easeX(100,10,false); // Move mc to an X of 100, smoothly, at “10” speed[/size]
[size=1]mc.easeY(100,10,false); // Move mc to a Y of 100, smoothly, at “10” speed[/size]