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

四方向からのテキストアニメーション

四方向から来るテキストアニメーション
参考→http://citizen.jp/arakigallery/
// 四方向から来るテキストアニメーション
// 参考→http://citizen.jp/arakigallery/
package
{
	import caurina.transitions.Tweener;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	[SWF(width = "465", height = "465", backgroundColor = "0xFFFFFF", frameRate = "30")]
	public class EveryDirectionT extends Sprite
	{
		private const txt:String = "サイト構築のためのトータルデザイン誌";
		private const tran:String = "easeOutElastic";
		private var tfList:Array = [];
		private var margin:Point = new Point(100, 200);
		private var cnt:uint;
		private var xpos:Number = 0;
		private var xposList:Array = [];
		
		
		public function EveryDirectionT():void
		{
			setText();
			setPoint();
			
			addEventListener(Event.ENTER_FRAME, onEnterHandler);
			stage.addEventListener(MouseEvent.CLICK, restart);
		}
		
		private function restart(e:MouseEvent):void
		{
			setPoint();
			addEventListener(Event.ENTER_FRAME, onEnterHandler);
		}
		
		private function setText():void
		{
			for (var i:uint=0; i<txt.length; i++)
			{
				var bmp:Bitmap = createText(txt.charAt(i));
				addChild(bmp);
				tfList.push(bmp);
			}
		}
		
		private function setPoint():void
		{
			cnt = 0;
			xpos = 0;
			xposList = [];
			Tweener.removeAllTweens();
			removeEventListener(Event.ENTER_FRAME, onEnterHandler);
			
			var point:Point;
			for each(var value:Bitmap in tfList)
			{
				point = getPoint(xpos);
				value.alpha = 0.0;
				value.x = point.x;
				value.y = point.y;
				xposList.push(xpos);
				xpos += value.width -4; // -4は文字間を詰める為
			}
		}
		
		private function onEnterHandler(e:Event):void
		{
			if(cnt < tfList.length)
			{
				Tweener.addTween(tfList[cnt], {delay:cnt*0.05, alpha:1.0, x:xposList[cnt] + margin.x, y:margin.y, time:0.5, transition:tran});
			}
			else
			{
				removeEventListener(Event.ENTER_FRAME, onEnterHandler);
			}
			cnt++;
		}
		
		private function getPoint(xpos:Number):Point
		{
			var rtn:Point;
			var random:uint = Math.random() * 4;
			
			switch (random)
			{
				case 0:
				rtn = new Point(0, margin.y);
				break;
				
				case 1:
				rtn = new Point(xpos + margin.x, 0);
				break;
				
				case 2:
				rtn = new Point(stage.stageWidth, margin.y);
				break;
				
				case 3:
				rtn = new Point(xpos + margin.x, stage.stageHeight);
				break;
				
				default:
				rtn = new Point(0, 0);
				break;
			}
			
			return rtn;
		}
		
		private function createText(value:String):Bitmap
		{
			var tf:TextField = new TextField();
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.text = value;
			var bmd:BitmapData = new BitmapData(tf.width, tf.height, true, 0x000000);
			bmd.draw(tf);
			var bmp:Bitmap = new Bitmap(bmd);
			
			return bmp;
		}
	}
}