The situation is this:
1/ Class Grid.as
- Obtain the value of the option chosen // score:Number
- Generate a new instance: generateTrivia // trivia:generateTrivia
- Send the score value using a method // trivia.sendScore(score)
2/ Class generateTriva
- Save the score value score private function sendScore(rScore:Number){ this.pt = rScore; } - I created a variable to update the score after the question is answered // private var finalScore:Number = 0; - When the user clicks on send button:
a. Validate the answer
b. update the finalScore
// finalScore = finalScore + this.pt; - Finally I update the textfield to show the score Note: I've observed that the first time when the user answer the question correctly the accumulator: finalScore works fine but after that I don't know why does not add the new value of the variable (this.pt ) to the stored result UPDATED: I found something. After the answer is validated, the instance is removed and back to grilla, then repeat the process by question. I should store the result of the validation and send it back to the grid class and then process accumulate the value
答案 0 :(得分:1)
您应该学习如何调试程序。错误可以是从未初始化的变量开始到“1”(参见那里的空格)转换为NaN。
最简单的方法是在trace()
和score
值更改的函数中添加pu
语句。更好的方法是在用户选择一个选项来回答并逐步执行执行监控变量时设置断点。