as3.0为文本字符配上飞入动画

 

 

package {
	import flash.display.*;
	import flash.text.*;
	import flash.geom.Point;
	import flash.events.*;
	import flash.utils.Timer;
	
	public class TextFly extends MovieClip {
		// 定义动画的常量
		static const spacing:Number = 50;//间隔
		static const phrase:String = "MeetLunay";
		static const numSteps:int = 50;
		static const stepTime:int = 20;
		static const totalRotation:Number = 360;//整体旋转
		static const startScale:Number = 0.0;
		static const endScale:Number = 2.0;//缩放结束
		static const startLoc:Point = new Point(250,0);//起始位置
		static const endLoc:Point = new Point(50,100);//结束位置
		private var letterFormat:TextFormat = new TextFormat("Courier",36,0x000000,true,false,false,null,null,TextFormatAlign.CENTER);
		
		// 跟踪动画的变量
		private var letters:Array = new Array();
		private var flySprite:Sprite;
		private var animTimer:Timer;
		
		public function TextFly() {
			// 保存所有元素sprite 
			flySprite = new Sprite();
			addChild(flySprite);
			
			// 为每个字母创建文本字段,并放入sprite中
			for(var i:int=0;i<phrase.length;i++) {
				var letter:TextField = new TextField();
				letter.defaultTextFormat = letterFormat;
				letter.embedFonts = true;
				letter.autoSize = TextFieldAutoSize.CENTER;
				letter.text = phrase.substr(i,1);
				letter.x = -letter.width/2;
				letter.y = -letter.height/2;
				var newSprite:Sprite = new Sprite();
				newSprite.addChild(letter);
				newSprite.x = startLoc.x;
				newSprite.y = startLoc.y;
				flySprite.addChild(newSprite);
				letters.push(newSprite);
			}
			
			// 开始动画
			animTimer = new Timer(stepTime,numSteps);
			animTimer.addEventListener(TimerEvent.TIMER,animate);
			animTimer.start();
		}
		
		public function animate(event:TimerEvent) {
			// 动画的长度
			var percentDone:Number = event.target.currentCount/event.target.repeatCount;
			
			// 改变位置, 尺寸和旋转
			for(var i:int=0;i<letters.length;i++) {
				letters[i].x = startLoc.x*(1.0-percentDone) + (endLoc.x+spacing*i)*percentDone;
				letters[i].y = startLoc.y*(1.0-percentDone) + endLoc.y*percentDone;
				var scale:Number = startScale*(1-percentDone)+endScale*percentDone;
				letters[i].scaleX = scale;
				letters[i].scaleY = scale;
				letters[i].rotation = totalRotation*(percentDone-1);
			}
		}
	}
}

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值