DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Actionscript Easer

05.07.2007
| 2006 views |
  • submit to reddit
        
// example usage: this.ease('x', 100, 4);
// lower speed value = faster
MovieClip.prototype.ease = function(prop, target, speed) {
	delta = this['_' + prop] - target;
	if (delta != 0) {
		this['_' + prop] = this['_' + prop] - (delta / speed);
		delta = this['_' + prop] - target;
		if (delta < .25 and delta > -.25) {
			this['_' + prop] = target;
			delta = 0;
		}
	}
};