In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Toggle direction of tween with BetweenAS3

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

// forked from beinteractive's 1. Simple tweens with BetweenAS3
package
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.Cubic;
	import org.libspark.betweenas3.tweens.ITween;
	
	public class Sample extends Sprite
	{
		
		private var _tween:ITween;
		
		public function Sample()
		{
			this._tween = BetweenAS3.parallel(
				BetweenAS3.tween(addNewBox(50), {x: 455}, {x: 20}, 1, Cubic.easeInOut),
				BetweenAS3.tween(addNewBox(100), {x: 455}, {x: 20}, 1, Cubic.easeInOut, 0.1),
				BetweenAS3.tween(addNewBox(150), {x: 455}, {x: 20}, 1, Cubic.easeInOut, 0.2),
				BetweenAS3.tween(addNewBox(200), {x: 455}, {x: 20}, 1, Cubic.easeInOut, 0.3)
			);
			this._tween.play();
			this.stage.addEventListener(MouseEvent.CLICK, this._reverse);
		}
		
		private function _reverse(e:MouseEvent):void {
			this._tween.stop();
			this._tween = BetweenAS3.reverse(this._tween);
			this._tween.play();
		}
		
		private function addNewBox(y:Number):Box
		{
			var box:Box = new Box();
			box.x = 20;
			box.y = y;
			addChild(box);
			return box;
		}
	}
}

import flash.display.Sprite;

internal class Box extends Sprite
{
	public function Box(size:int = 20)
	{
		graphics.beginFill(0);
		graphics.drawRect(-size / 2, -size / 2, size, size);
		graphics.endFill();
	}
}