累积得分在AS3 [英] Accumulate score in AS3

查看:164
本文介绍了累积得分在AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 的情况是这样的:
 



    1 /类 Grid.as  
     - 获得选择// 评分选项的值:数
     - 生成一个新的实例:generateTrivia // 花絮:generateTrivia
     - 发送使用方法// trivia.sendScore(分)
分数值     2 /类 generateTriva
      - 保存分值得分       私有函数sendScore(rScore:号码){          this.pt = rScore;       }      - 我创建了一个变量,以更新得分的问题得到解答后,      // 私人变种finalScore:数量= 0;      - 当用户点击发送按钮:
    一个。验证答案
    湾更新finalScore
     // finalScore = finalScore + this.pt;      - 最后,我更新了文本框来显示比分     注意:     我观察到,第一次当用户正确回答的问题     蓄电池:finalScore工​​作正常,但在那之后,我不知道为什么不增加新的     可变(this.pt)的所存储的结果值     更新时间::我发现了什么。后的回答为验证,实例被去除并返回到格里拉,然后通过质询重复上述过程。我应该存储验证的结果,其发回给电网类,然后过程积累的价值

解决方案

您应该学会如何调试程序。错误操作可能是由未初始化的变量开始为1(见有空格)转换为NaN。

最简单的方法是添加跟踪()在函数的语句,你的分数 PU 值的变化。更好的方法是,当用户选择一个选项来回答,并通过执行监控变量步骤来设置一个断点。

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

解决方案

You should learn how to debug a program. An error can be something started from uninitialized variable to "1 " (see the space there) converted to NaN.

The simplest way is to add trace() statements in the functions where your score and pu values change. Better way is to set a breakpoint when user selects an option to answer and step through the execution monitoring variables.

这篇关于累积得分在AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆