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

forked from: Hello, BetweenAS3!

// forked from beinteractive's Hello, BetweenAS3!
package
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	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()
		{
			// Create character fields
			var characters:Array = getCharacters('Hello, BetweenAS3!');
			
			// Create each character tween
			var cl:uint = characters.length;
			var ctweens:Array = new Array(cl);
			for (var i:uint = 0; i < cl; ++i) {
				ctweens[i] = BetweenAS3.delay(BetweenAS3.tween(characters[i], null, {y: -30}, 0.8, Back.easeOutWith(2.2)), 1.0 + 0.2 * i);
			}
			var ctween:ITween = BetweenAS3.parallelTweens(ctweens);
			
			// Create go and back tween
			_t = BetweenAS3.serial(
				ctween,
				BetweenAS3.delay(BetweenAS3.reverse(ctween), 3)
			);
			
			
			// 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();
		}
		
		private function getCharacters(text:String):Array
		{
			var l:uint = text.length;
			var result:Array = new Array(l);
			var format:TextFormat = new TextFormat('Arial', 24, 0x000000, true);
			var textHeight:Number = 0;
			var totalWidth:Number = 0;
			var i:uint;
			var tf:TextField;
			for (i = 0; i < l; ++i) {
				tf = new TextField();
				tf.defaultTextFormat = format;
				tf.autoSize = TextFieldAutoSize.LEFT;
				tf.text = text.charAt(i);
				tf.x = totalWidth;
				textHeight = Math.max(textHeight, tf.textHeight);
				totalWidth += tf.textWidth + 2;
				result[i] = tf;
			}
			var offsetX:Number = (stage.stageWidth - (totalWidth - 2)) / 2;
			var offsetY:Number = (stage.stageHeight - textHeight) / 2;
			for (i = 0; i < l; ++i) {
				tf = result[i] as TextField;
				tf.x += offsetX;
				tf.y += offsetY;
				addChild(tf);
			}
			return result;
		}
	}
}