Tween Test (Controling Tweens by Easing Functions)
import gs.easing.*;
/**
* Copyright 9re ( http://wonderfl.net/user/9re )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ekIh
*/
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
//import gs.easing.*;
import mx.effects.easing.*;
import gs.TweenLite;
[SWF(frameRate="29", width="465", height="465", background="#ffffff")]
public class TweenTest extends Sprite {
private const Quad:* = Quadratic;
private const N:int = 15;
private var _sprites:Vector.<Sprite> = new Vector.<Sprite>();
private var _ta:int = 0;
public function TweenTest() {
var i:int, j:int, l:int = 465 / N;
var sp:Sprite;
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
sp = new Sprite();
sp.graphics.beginFill(0xff, 0.2);
sp.graphics.drawRect(- l / 2, - l / 2, l, l);
sp.graphics.endFill();
sp.x = l * j + l / 2; sp.y = l * i + l / 2;
addChild(sp);
_sprites.push(sp);
}
}
sp = new Sprite();
sp.graphics.beginFill(0xff0000, 0.3);
sp.graphics.drawRect(0, 0, 465, 465);
sp.graphics.endFill();
addChild(sp);
sp.buttonMode = true;
sp.tabEnabled = false;
sp.addEventListener(MouseEvent.CLICK, clickHandler);
}
private function clickHandler(e:MouseEvent):void {
var len:int = _sprites.length, i:int = 0;
var sp:Sprite;
var time:Number, delay:Number, u:Number, v:Number, w:Number;
while (i < len) {
sp = _sprites[i];
u = i % N - N / 2; v = i / N - N / 2;
w = (u * v < 0) ? Math.abs(u - v) : Math.abs(u + v);
time = Quad.easeOut(w, 2.0, -1.0, N);
delay = Quad.easeOut((_ta < 1) ? N - w : w, 0.2, 1.0, N);
TweenLite.to(sp, time, {alpha: _ta, scaleX: _ta, scaleY: _ta, delay: delay, ease:Quad.easeOut});
++i;
}
_ta = 1 - _ta;
}
}
}