开发者

actionscript 3 sleep?

I have a simple actions开发者_开发问答cript function

var string:String = "TEXT REMOVED";
var myArray:Array = string.split("");
addEventListener(Event.ENTER_FRAME, frameLooper);

function frameLooper(event:Event):void {
    if(myArray.length > 0) {
        text1.appendText(myArray.shift());
    }else{
        removeEventListener(Event.ENTER_FRAME, frameLooper);
    }
}

And I want to have it sleep after calling the framelooper so it is a little bit slower. How could I do this?

btw, I'm fairly new and found this code on a tutorial, it's a text typing effect, if there is a better way of doing this please let me know.


Use a Timer:

var string:String = "TEXT REMOVED";
var myArray:Array = string.split("");
var timer : Timer = new Timer (1000, myArray.length);
timer.addEventListener (TimerEvent.TIMER, frameLooper);
timer.start();

function frameLooper(event:Event):void {
    text1.appendText(myArray.shift());
}

This will execute the frameLooper on every second for exactly as many times as the length of the array.


I'm not saying this is better than the timer method, just an option

var string:String = "TEXT REMOVED";
var myArray:Array = string.split("");
addEventListener(Event.ENTER_FRAME, frameLooper);

const WAIT_TIME:int = 10;
var i:int = 0;
function frameLooper(event:Event):void {
    if(myArray.length > 0) {
        if(i==0){ 
            trace(myArray.shift()); 
            i = WAIT_TIME;
        };
    } else {
        removeEventListener(Event.ENTER_FRAME, frameLooper);
    }
    i--;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜