Customising Easing Functions

by 9re
...
@author 9re
♥0 | Line 41 | Modified 2009-06-16 23:32:06 | MIT License
play

ActionScript3 source code

/**
 * Copyright 9re ( http://wonderfl.net/user/9re )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kI39
 */

package  
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.setTimeout;
	
	import gs.easing.*;
	import gs.TweenLite;
	/**
	 * ...
	 * @author 9re
	 */
	[SWF(background="#ffffff", frameRate="31", width="465", height="465")]
	public class ForthAndBack extends Sprite
	{
		
		public function ForthAndBack() 
		{
			var easingClasses:Array = [Back, Bounce, Circ, Cubic, Elastic, Expo, Linear, Quad, Quart, Quint, Sine, Strong];
			var s:int = 30;
			
			var sp:Sprite = new Sprite();
			sp.graphics.beginFill(0xff0000, 0.3);
			sp.graphics.drawCircle(s, 0, s);
			sp.graphics.endFill();
			
			sp.y = stage.stageHeight / 2;
			addChild(sp);
			
			var tf:TextField = new TextField();
			tf.defaultTextFormat = new TextFormat("Arial", 16, 0x666666, true);
			tf.x = 10;
			tf.y = 10;
			addChild(tf);
			
			var i:int = 0;
			var f:Function = function (easingClass:*):void {
				tf.text = easingClass.toString().replace("[class ", "").replace("]", "");
				TweenLite.to(sp, 1.2, { x: stage.stageWidth - sp.width, delay: 0.5,
				ease:function (t:Number, b:Number, c:Number, d:Number):Number {
					return (t <d/2) ? easingClass.easeIn(t, b, c, d / 2) : easingClass.easeIn(d - t, b, c, d / 2);
				}, onComplete: function ():void {
					sp.x = 0;
					setTimeout(f, 1000, easingClasses[++i % easingClasses.length]);
				} } );
			};
			f(Back);
		}
	}
}