0

Flash/AS3初心者はこちら。

テキストを文字ごとに表示しようとしています(これはうまく機能しています)。ただし、ピリオド/文の終わりが発生するたびに、アニメーションを最大 500 ミリ秒遅らせる必要があります。これまでのところ、私のコードの関連部分は次のようになります。

public function displayLoop(e:Event):void
    {
        if (pos == textToDisplay.length - 1)
        {
            stop();
            return;
        }

        firstParagraph.appendText(textToDisplay.charAt(pos));
        if (textToDisplay.charAt(pos) == String.fromCharCode(46))
        {
            //here's where I want to delay??
        }
        pos++;
    }

この場合、firstParagraph はダイナミック テキスト オブジェクトの名前、textToDisplay は文字ごとに表示されるテキストの文字列、pos は単にテキストを表示するときの位置です。それを追跡します。

おそらくTimer EventHandlerを使用して、この問題に対する簡単な解決策があると思いますか?

誰かが提供しなければならない助けに感謝します、ありがとう!

4

2 に答える 2

0

タイマーにはカウンターが組み込まれているため、位置を追跡する必要はありません。

import flash.text.TextField;
import flash.utils.Timer;
import flash.events.TimerEvent;

var textToDisplay:String = 'AB.CDE.FGHI.JKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
var tf:TextField = new TextField()
tf.width = 500
tf.wordWrap = true
tf.height = 400
addChild(tf)
var timer:Timer = new Timer(100)
timer.addEventListener(TimerEvent.TIMER, onTimer)
timer.start()
function onTimer(e:TimerEvent):void{
    timer.delay = 100
    tf.appendText(textToDisplay.slice(timer.currentCount-1,timer.currentCount))
    if(timer.currentCount == textToDisplay.length){
        timer.stop()
    }
    if(textToDisplay.slice(timer.currentCount-1,timer.currentCount) == '.'){
        timer.delay = 500
    }
}
于 2013-08-30T14:11:11.440 に答える