/** * VERSION: 0.5 * DATE: 2010-12-01 * AS2 * UPDATES AND DOCS AT: http://www.greensock.com/ **/ import mx.utils.Delegate; /** * Most easing equations give a smooth, gradual transition between the start and end values, but SteppedEase provides * an easy way to define a specific number of steps that the transition should take. For example, if mc._x is 0 and you * want to tween it to 100 with 5 steps (20, 40, 60, 80, and 100) over the course of 2 seconds, you'd do:

* * TweenLite.to(mc, 2, {_x:100, ease:SteppedEase.create(5)});

* * EXAMPLE CODE

* import com.greensock.TweenLite;
* import com.greensock.easing.SteppedEase;

* * TweenLite.to(mc, 2, {_x:100, ease:SteppedEase.create(5)});

* * //or create an instance directly
* var steppedEase:SteppedEase = new SteppedEase(5);
* TweenLite.to(mc, 3, {_y:300, ease:steppedEase.ease}); *


* * Note: SteppedEase is optimized for use with the GreenSock tweenining platform, so it isn't intended to be used with other engines. * Specifically, its easing equation always returns values between 0 and 1.

* * Copyright 2011, GreenSock. All rights reserved. This work is subject to the terms in http://www.greensock.com/terms_of_use.html or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership. * * @author Jack Doyle, jack@greensock.com */ class com.greensock.easing.SteppedEase { /** @private **/ private var _steps:Number; /** @private **/ private var _stepAmount:Number; /** Easing equation to which tweens should refer. **/ public var ease:Function; /** * Constructor * * @param steps Number of steps between the start and the end values. */ public function SteppedEase(steps:Number) { _stepAmount = 1 / steps; _steps = steps + 1; this.ease = Delegate.create(this, easeProxy); //to ensure scope is correct in AS2. } /** * This static function provides a quick way to create a SteppedEase and immediately reference its ease function * in a tween, like:

* * TweenLite.to(mc, 2, {_x:100, ease:SteppedEase.create(5)});
*
* * @param steps Number of steps between the start and the end values. * @return The easing function that can be plugged into a tween */ public static function create(steps:Number):Function { var se:SteppedEase = new SteppedEase(steps); return se.ease; } /** * Easing function that interpolates values. * * @param t time * @param b start (should always be 0) * @param c change (should always be 1) * @param d duration * @return Result of the ease */ public function easeProxy(t:Number, b:Number, c:Number, d:Number):Number { var ratio:Number = t / d; if (ratio < 0) { ratio = 0; } else if (ratio >= 1) { ratio = 0.999999999; } return ((_steps * ratio) >> 0) * _stepAmount; } /** Number of steps between the start and the end values. **/ public function get steps():Number { return _steps - 1; } }