所以我在第342行收到一个错误,它是
myTextField.text = object[curPart]["text"]
它说一个术语是未定义的。跟踪curPart给了我一个null值,尽管在为该值运行即时代码的代码中,curPart是part3。没有什么能改变它。这是在它之前运行的,一个类型写入效果函数。
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部分之前跳过打字过程,也不会发生这种情况。)
edit:我刚刚意识到的另一件事是,第342行永远不应该运行,因为textFinished应该等于true(之前是这样,但当我按下空格时,它神奇地不是。我不会在任何地方将其更改为false,除非在错误发生时没有运行的部分)
没关系。找到它不起作用的原因。愚蠢的用户错误。