AS3学习之路(1) 一个简单的实例, 打字效果(0 位领导批示)
- 2009-07-24
- 分类:ActionScript
- 作者:银子
- 575 位领导视察
最近开始学习AS. 在日志上胡乱记录几个实例..以备回顾..
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++; } } } |















