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

Textアニメーションその1(練習)

Get Adobe Flash player
by plus-tic 11 Aug 2010
/**
 * Copyright plus-tic ( http://wonderfl.net/user/plus-tic )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mr5j
 */

package {
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.events.MouseEvent;
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;
    import flash.events.Event;
    
    public class MytextField extends Sprite {
        public var fld:TextField;
        public var msg:String = "無理を通して道理を蹴飛ばす!!";
        public var timer:Timer;
        //コンストラクタ
        public function MytextField() {
            //テキストの書式
            var tf:TextFormat = new TextFormat();
            tf.font = "_sans";
            tf.size = 18;
            tf.color = 0xffffff;
            tf.align = TextFormatAlign.CENTER;
            //テキストフィールドの作成
            fld = new TextField();
            fld.x = 100;
            fld.y = 50;
            fld.width = 250;
            fld.background = true;
            fld.backgroundColor = 0x000000;
            fld.autoSize = TextFieldAutoSize.CENTER;;
            //テキスト書式の初期値
            fld.defaultTextFormat = tf;
            addChild(fld);  
            //100ミリ秒ごとにtimerイベントを発生
            timer = new Timer(100,fld.length); 
            timer.addEventListener(TimerEvent.TIMER,timehandler);
            timer.start();         
        }
        //1文字ずつ追加
        public function timehandler(e:TimerEvent):void{
            //イベント回数を利用して取り出す文字位置をカウントアップ
            var char:String = msg.charAt(timer.currentCount-1);
            //取り出した文字をテキストフィールドに追加
            fld.appendText(char);
        }
    }
}