奇怪的错误AS3。术语未定义

时间:2015-11-24 14:19:45

标签: actionscript-3

所以我在第342行收到错误

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

它说术语未定义。跟踪curPart给了我一个空值,虽然在代码中只运行了那个时刻,curPart是第3部分。什么都没改变。这就是它之前运行的一种类型写作效果函数。

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;
            }
        }
    }

另一个奇怪的事情是,如果我通过按空格键完成类型书写效果,则不会发生错误:

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
        }
    }
}

我查看了几个小时的代码。文本在第3部分和第3部分内部存在,考虑到如果我通过按空格跳过键入过程,它可以工作。 (如果我在第3部分之前跳过打字过程,也不会发生这种情况。)

编辑:我刚才意识到的另一件事,第342行永远不应该被运行,因为textFinished应该等于true(之前的时刻,但是当我按空格时,它神奇地不是。我不会将其更改为false除错误发生时未运行的部分以外的任何地方)

1 个答案:

答案 0 :(得分:0)

没关系。找到它为什么不起作用。愚蠢的用户错误。