0

コードに関するちょっとしたヒントを得るためにこのサイトを使用するのが大好きで、自分でできるすべてのエラーを解決しようとしています。しかし、これは私を何日も困惑させました。私はそれをクラックすることはできません。

RangeError: エラー #2006: 指定されたインデックスが範囲外です。flash.text::TextField/setTextFormat() で BibleProgram_fla::MainTimeline/checkAgainstBible() で BibleProgram_fla::MainTimeline/compileInputString() で BibleProgram_fla::MainTimeline/spaceBuild()

function spaceBuild(event:Event):void //This program runs every frame
{
    compileInputString();
}

function compileInputString():void
{
    inputVerse = inputText.text; // takes text from the input field

    inputVerse = inputVerse.toLowerCase();
    inputVerse = inputVerse.replace(rexWhiteSpace, "");  //Removes spaces and line breaks
    inputVerse = inputVerse.replace(rexPunc, ""); // Removes punctuation

    inputVerse = addSpaces(inputVerse); //adds spaces back in to match the BibleVerse
    inputVerse = addCaps(inputVerse); //adds capitalization to match the BibleVerse
    checkAgainstBible();
}

function checkAgainstBible()
{
    outputText.text = inputVerse; // sets output text to be formatted to show which letters are wrong

    for(var n:Number = 0; n < inputText.length; n++)
    {
        var specLetter:String = inputVerse.charAt(n);

        if(specLetter != bibleVerse.charAt(n))
        {
            outputText.setTextFormat(red, n); // sets all of the wrong letters to red
        }

    }
}

プログラムを実行して、BibleVerse よりも長い文字列を入力すると、エラーが返されますが、修正方法がわかりません。

あなたが私を助けるのに十分な情報を提供したことを願っています. さらにコードなどが必要な場合は、お問い合わせください。前もって感謝します!!

4

1 に答える 1

1

フォーマットの色を赤に設定するときに、n が outputText の文字数よりも大きい場合、そのエラーが発生します。また、inputVerse が私が見ることができないすべての正規表現操作がそれに行われました。したがって、ほとんどの場合、これらの操作は文字を短縮しているため、outputText.text は本来よりも短くなり、inputText.length をループすると、outputText の最後に到達すると、n が文字長を超えてしまうため、次のようになります。そのエラー(それがエラーです-そこにないものにアクセスしようとしています)。だから私がそれを見る方法は(文字列で構成された例を使用して)です。

// Pseudo code...
inputVerse=inputText.text; // (lets say its "Thee ")
// inputVerse and inputText.text now both have 5 characters
inputVerse=lotsOfOperations(inputVerse);
// inputVerse now only has 4 characters (got rid of the " " at the end)
outputText.text=inputVerse;
// outputText.text now has the new 4 character
for(var n:Number = 0; n < inputText.length; n++)
// loops through inputText.length (so it loops 5 times)
outputText.setTextFormat(red, n);
// if n=4 (since n starts at 0) from the inputText.length, then when it access
//outputText.setTextFormat(red,n) it is accessing a character of outputText.text
//that is at the end and not there. outputText.text is too short for the loop.

したがって、あなたの問題は、inputVerse への操作が短すぎて他の文字列と比較できないことです。他のコードがわからないため、何が問題なのかはわかりませんが、これがエラーが発生する理由です。ご不明な点がございましたら、コメントしてください。または、不足しているものをお知らせください。

于 2013-11-06T23:57:26.157 に答える