0
votes

I've loved using this site for little tips on code, and I try to solve all the errors I can by myself. However, this one has had me stumped for days. I just can't crack it.

RangeError: Error #2006: The supplied index is out of bounds. at flash.text::TextField/setTextFormat() at BibleProgram_fla::MainTimeline/checkAgainstBible() at BibleProgram_fla::MainTimeline/compileInputString() at 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
        }

    }
}

Whenever I run the program and type a string longer than the BibleVerse, it returns the error, but I cannot figure out how to fix it.

I hope I provided enough information for you to help me. If you need more code or something, please ask! Thanks in advance!!

1

1 Answers

1
votes

Well, you would get that error if n is greater than the number of characters in the outputText when it sets its format color to red, and it looks like your outputText's characters are extended or shortened when you make it equal to your inputVerse because inputVerse had all the regex operations that i can't seen done to it. So most likely these operations are shortening the characters and so outputText.text is shorter than it should be and when it loops over the inputText.length, when it gets to the end of the outputText, n goes past its character length and so you get that error (That is what the error is - you are attempting to access something that is not there). So the way i see it is (using example made up strings);

// 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.

So, your problem is that your operations to inputVerse are making it too short to compare to the other strings, I don't know your other code so I can't say whats wrong, but this is why you are getting the error. Please comment if you have any questions or to notify me of what I am missing.