Tweener パターン
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/skCz
*/
package {
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
var ar:Array = new Array();
ar.push(new Tw("linear"));
ar.push(new Tw("easeInSine"));
ar.push(new Tw("easeOutSin"));
ar.push(new Tw("easeInOutSine"));
ar.push(new Tw("easeInQuad"));
ar.push(new Tw("easeOutQuad"));
ar.push(new Tw("easeInOutQuad"));
ar.push(new Tw("easeInCubic"));
ar.push(new Tw("easeInOutCubic"));
ar.push(new Tw("easeInQuart"));
ar.push(new Tw("easeInBack"));
ar.push(new Tw("easeInBounce"));
ar.push(new Tw("easeOutBack"));
ar.push(new Tw("easeInOutElastic"));
ar.push(new Tw("easeOutBounce"));
ar.push(new Tw("easeInOutBounce"));
for(var i:int=0;i<ar.length;i++){
addChild(ar[i]);
ar[i].x = (i%4)*110;
ar[i].y = Math.floor(i/4)*90;
}
}
}
}
import caurina.transitions.Tweener;
import flash.display.*;
import flash.text.*;
import flash.events.*;
class Tw extends Sprite{
private var s:Sprite = new Sprite();
private var st:Date;
private var sec:Number = 3;
private var _width:Number=100;
private var _height:Number=60;
private var _trans:String;
private var tf:TextField = new TextField();
public function Tw(str:String = "linear"){
this.buttonMode=true;
graphics.clear();
graphics.lineStyle(0,0);
graphics.beginFill(0xddddff);
graphics.drawRect(0,0,_width,_height);
graphics.endFill();
addChild(tf);
_trans = str;
tf.text = str;
tf.width = tf.textWidth+5;
tf.height = tf.textHeight+5;
tf.y = _height;
tf.x = _width/2-tf.width/2;
addEventListener(MouseEvent.CLICK,onClick);
draw();
}
private function onClick(e:MouseEvent):void{
draw();
}
public function draw(t:Number=3):void{
sec = t;
graphics.clear();
graphics.lineStyle(0,0);
graphics.beginFill(0xddddff);
graphics.drawRect(0,0,_width,_height);
graphics.endFill();
this.addEventListener(Event.ENTER_FRAME,onFrame);
s.y = _height;
s.x = 0;
st = new Date();
Tweener.addTween(s,{
time:sec,
y:0,
transition: _trans
});
graphics.lineStyle(1.5,0x00aaff,0.95);
graphics.moveTo(s.x,s.y);
}
private function onFrame(e:Event):void{
var now:Date = new Date();
var t1:Number = (now.valueOf() - st.valueOf()) / 1000;//開始からの時間
var t2:Number = (t1/sec);
s.x = _width*t2;
if(t2<1)graphics.lineTo(s.x,s.y);
else this.removeEventListener(Event.ENTER_FRAME,onFrame);
}
}