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

5. Tween controlling with BetweenAS3

Get Adobe Flash player
by beinteractive 13 Aug 2009
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 = addNewBox(100);
			var box2:Box = addNewBox(200);
			
			// Create a tween
			_t = BetweenAS3.parallel(
				BetweenAS3.tween(box1, {x: 220}, {x: 20}, 1.2, Bounce.easeOut),
				BetweenAS3.tween(box2, {x: 20}, {x: 220}, 1.2, Bounce.easeOut)
			);
			
			// 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.
		}
		
		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()
	{
		graphics.beginFill(0);
		graphics.drawRect(-10, -10, 20, 20);
		graphics.endFill();
	}
}