mardi 24 novembre 2015

Weird error AS3. Term undefined

so I'm getting an error at line 342 which is

myTextField.text = object[curPart]["text"]

it says that a term is undefined. Tracing curPart gives me a null value, although in code that runs literally moments for that one, curPart is part3. Nothing changes it. This is what runs before it, a type writing effect function.

private function addCharackter():void
{
    if (!textFinished)
    {
        // add the charackter to the Textfield
        myTextField.text = object[curPart]["text"].substring(0,counter)
        counter++
        trace(curPart) // prints "part3"
        // if you reached the end of the String stop Timer
        if (counter == object[curPart]["text"].length+1 && !textFinished)
        {
            textFinished = true;
            trace("Text finished:",textFinished)
            clearInterval(sInt)
            counter = 0;
            if (object[curPart]["text"].indexOf("What do you do?") >= 0)
            {
                trace("H!!!")
                choosing = true
                createOptions();
            }
            if (object[curPart]["text"].indexOf("What do you do?") >= 0)
            {
                dead = true;
            }
        }
    }

Another weird thing is that the error doesn't happen if I finish the type writing effect by pressing space which is done here:

public function onEnter(key:KeyboardEvent):void
{
    if (key.charCode == 32)
    {
        if (dead && textFinished && !choosing)
        {
            curPart = object[curPart]["lastPart"]
            textFinished = false
            dead = false;
            myTextField.text = ""
            counter = 0;
            sInt = setInterval(addCharackter, textSpeed)
        }
        if (!textFinished && !choosing && !dead)
        {
            trace(textFinished)
            trace("finishing")
            trace(curPart)
            myTextField.text = object[curPart]["text"]
            if (object[curPart]["text"].indexOf("What do you do?") >= 0)
            {
                trace("H!")
                choosing = true
                createOptions();
            }
            if (object[curPart]["text"].indexOf("You have died") >= 0)
            {
                dead = true;
            }
            clearInterval(sInt)
            textFinished = true;
        }
        else if (textFinished && !choosing && !dead)
        {
            trace("Hi!!!!")
            curPart = object[curPart]["nextPart"]
            myTextField.text = ""
            counter = 0;
            sInt = setInterval(addCharackter, textSpeed)
            textFinished = false
        }
    }
}

I've looked through my code for hours. text is inside part3 and part3 DOES exist, considering it works if I skip the typing process by pressing space. (it also doesn't happen if I were to skip the typing process before part3.)

edit: Another thing that I just realised, line 342 should never be ran because textFinished should equal true (which it is moments before, but when I press space, it magically isn't. I don't change it to false anywhere except in parts that aren't running when the error happens)

Aucun commentaire:

Enregistrer un commentaire