package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.MouseEvent;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
import org.libspark.betweenas3.easing.*;
public class Sample extends Sprite
{
public function Sample()
{
var box1:Box = new Box();
var box2:Box = new Box();
box1.y = 100;
box2.y = 200;
// Add each box before tween, and remove each box after tween.
_t = BetweenAS3.serial(
BetweenAS3.addChild(box1, this),
BetweenAS3.tween(box1, {x: 220}, {x: 20}, 1.2, Bounce.easeOut),
BetweenAS3.removeFromParent(box1),
BetweenAS3.addChild(box2, this),
BetweenAS3.tween(box2, {x: 20}, {x: 220}, 1.2, Bounce.easeOut),
BetweenAS3.removeFromParent(box2)
);
// Important point:
// When this tween is replayed after finished playing,
// state of each box (added/removed) will be restored.
// Set to be never stop
_t.stopOnComplete = false;
// Start the tween
_t.play();
// MouseUp listener
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
private var _t:ITween;
private function mouseUpHandler(e:MouseEvent):void
{
// Stop the tween if playing
// Start the tween if stopping
_t.togglePause();
// Note: You can use gotoAndPlay(time) or gotoAndStop(time) too.
}
}
}
import flash.display.Sprite;
internal class Box extends Sprite
{
public function Box()
{
graphics.beginFill(0);
graphics.drawRect(-10, -10, 20, 20);
graphics.endFill();
}
}