AS3学习之路(1) 一个简单的实例, 打字效果(0 位领导批示)

最近开始学习AS. 在日志上胡乱记录几个实例..以备回顾..

?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package
{
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	import flash.events.*;
	import flash.utils.Timer;
 
	public class ClassTyped extends MovieClip
	{
		var txt:TextField = new TextField();
		var txtF:TextFormat = new TextFormat();
		var cont:String = new String();
		var i:uint = 0;
 
		// 构造函数
		public function ClassTyped()
		{
			cont = "打字效果测试. By Silver...........";
			txtF.font = "微软雅黑";
			txtF.size = 14;
			txtF.color = 0x669900;
			txt.defaultTextFormat = txtF;
 
			var timer:Timer = new Timer(120, cont.length);
			timer.addEventListener(TimerEvent.TIMER, timerHandler);
			timer.start();
		}
 
		private function timerHandler(event):void
		{
			txt.selectable = false;
			txt.appendText(cont.charAt(i));
			txt.autoSize = TextFieldAutoSize.LEFT;
			txt.wordWrap = true;
			txt.width = 200;
			addChild(txt);
			txt.x = (txt.stage.stageWidth - txt.width) / 2;
			txt.y = (txt.stage.stageHeight - txt.height) / 2;
			i++;
		}
	}
}

源文件下载

相关文章

分享到新浪微博 推荐到豆瓣 分享到 Google Reader 加入Google书签 嘀咕一下 分享到饭否 分享到做啥 分享到叽歪 分享到鲜果 加入QQ书签 加入百度搜藏 加入雅虎书签 分享到垦一垦

银子曰:还没有领导题词?

请领导指示

验证码 (必须)

Additional comments powered by BackType

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志