flash on 2010-2-16

by aass
♥0 | Line 41 | Modified 2010-02-16 19:08:52 | MIT License
play

ActionScript3 source code

/**
 * Copyright aass ( http://wonderfl.net/user/aass )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/b2ds
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    public class MyTextField extends Sprite {
    		public var fld:TextField;
    		public var tf:TextFormat;
    		public var msg:String = "Wonderflと\nActionScript3.0\nワンダフルな世界!";
    		public var charPos:uint;
    		public var counter:uint;
    		public var currentMsg:String;
    		public var timer:Timer;
    		public var offset:int = Math.floor(30*Math.random())+5;
    		
        public function MyTextField() {
            // write as3 code here..
      		tf = makeTextFormat("_typewriter",24,0x000000);
      		//テキストフィールドの作成
      		fld = new TextField();
      		fld.x = 50;
      		fld.y = 50;
      		fld.autoSize = TextFieldAutoSize.LEFT;
      		//書式の初期値
      		fld.defaultTextFormat = tf;
      		addChild(fld);
      		//アニメーション用のループを行うタイマー
      		timer = new Timer(10);
      		timer.addEventListener(TimerEvent.TIMER,timerHandler);
      		timer.start();
        }
        //書式の作成
        public function makeTextFormat(font:String, size:uint, color:uint):TextFormat{
        		var tf:TextFormat = new TextFormat();
        		tf.font = font;
        		tf.size = size;
        		tf.color = color;
        		return tf;
        }
        //文字コードを探りながら1文字ずつ追加
        public function timerHandler(event:TimerEvent):void {
        		//表示したい文字コードよりoffsetだけ小さい文字コード
        		var startCharCode:uint = msg.charCodeAt(charPos)-offset;
        		//文字コードを文字に変換
        		var char:String = String.fromCharCode(startCharCode + counter);
        }
    }
}