テキスト順ぐり&クリック表示

by pasodania
テキスト順ぐり&クリック表示

♥0 | Line 51 | Modified 2009-10-22 17:49:14 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.events.MouseEvent;
    public class FlashTest extends Sprite {
        public var txt:TextField;
        public var msgs:Array;
        public var current:int;
        public var str:String = "testABCDEFGtestssaあいう";
        public var cnt:int = 0;
        public var msgcmp:Boolean;
        public function FlashTest() {
            // write as3 code here..
            msgs = new Array();
            msgs.push("テスト文章");
            msgs.push("テスト文章1");
            msgs.push("テスト文章2:ちょっと長い文章テスト");
            msgs.push("テスト文章3:さらに長い文章をテストトトトトトトトトトト");
            msgs.push("aaaaa\nvasdasda\naaaaOK");
            current = 0;
            
            txt = new TextField();            
            txt.autoSize = "left";
            addChild(txt);

            var myt:Timer = new Timer(100, 0);
            myt.addEventListener(TimerEvent.TIMER, show);
            myt.start();
            stage.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
                // Next Message
                if(msgcmp){
                    msgcmp = false;
                    current++;
                    cnt = 0;
                } else {
                    // end of message showing
                    msgcmp = true;
                    var len:int = String(msgs[current]).length;
                    txt.appendText(String(msgs[current]).substr(cnt, len-cnt) + "\n");
                }
            });
        }
        
        public function show(e:TimerEvent):void{
            var len:int = String(msgs[current]).length;
            if(!msgcmp && cnt < len){
                cnt++;
                txt.appendText(String(msgs[current]).substr(cnt - 1, 1));            
            } else if( !msgcmp && cnt >= len ){
                msgcmp = true;
                txt.appendText("\n");
            }
        }
    }
}