跟踪一系列简单的多项选择网络表单答案
keeping track of a series of simple multiple choice web form answers
这是我正在尝试使用的代码,这似乎合乎逻辑。但似乎没有用。
MyAsFileName.prototype.getTotalScore = function() {
var totalScore = 0;
for (var i = 0; i < allQuestions.length; i++) {
totalScore += allQuestions[i].getCalculatedScore();
if (currentModule.allQuestions[i].parent.questionCorrect == true) {
knowledgePoints++;
} else {
knowledgePoints--;
}
}
debugLog("Total score: " + totalScore);
debugLog(knowledgePoints);
return totalScore;
}
我allQuestions
定义如下:
var allQuestions = Array();
我将 knowledgePoints
定义为:
this.knowledgePoints = 10;
我将 questionCorrect
定义为:
this.questionCorrect = false;
第二次新尝试 使用新 class 作为下面建议的答案 (暂时注释掉,直到我弄清楚如何开始工作):
// package
// {
/*public class Quiz {
//public
var knowledgePoints: int = 10;
//public
var allQuestions: Array = new Array;
//public
var questionCorrect: Boolean = false;
//public
function getTotalScore(): int {
var totalScore: int = 0;
for (var i = 0; i < allQuestions.length; i++) {
totalScore += allQuestions[i].getCalculatedScore();
if (currentModule.allQuestions[i].parent.questionCorrect) {
knowledgePoints++;
} else {
knowledgePoints--;
}
}
debugLog("Total score: " + totalScore);
debugLog(knowledgePoints);
return totalScore;
}
}*/
//}
上面的代码在 Flash 控制台中输出了两个错误:
错误 1. 在 class.
之外使用的属性
错误2。无法加载'Int'。
这是一种奇怪的(并且实际上是非 AS3 方式)执行此操作的方式。不要创建一个未命名的闭包,它从谁知道的地方引用奇怪的变量,你应该把它变成一个普通的 AS3 class,类似的东西(在一个名为 Quiz.as 的文件中):
package
{
public class Quiz
{
public var knowledgePoints:int = 10;
public var allQuestions:Array = new Array;
public var questionCorrect:Boolean = false;
public function getTotalScore():int
{
var totalScore:int = 0;
// Your code does not explain how you will that Array.
// It is initially an empty Array of length 0.
for (var i = 0; i < allQuestions.length; i++)
{
totalScore += allQuestions[i].getCalculatedScore();
if (currentModule.allQuestions[i].parent.questionCorrect)
{
knowledgePoints++;
}
else
{
knowledgePoints--;
}
}
// Not sure what it is.
debugLog("Total score: " + totalScore);
debugLog(knowledgePoints);
return totalScore;
}
}
}
这是我正在尝试使用的代码,这似乎合乎逻辑。但似乎没有用。
MyAsFileName.prototype.getTotalScore = function() {
var totalScore = 0;
for (var i = 0; i < allQuestions.length; i++) {
totalScore += allQuestions[i].getCalculatedScore();
if (currentModule.allQuestions[i].parent.questionCorrect == true) {
knowledgePoints++;
} else {
knowledgePoints--;
}
}
debugLog("Total score: " + totalScore);
debugLog(knowledgePoints);
return totalScore;
}
我allQuestions
定义如下:
var allQuestions = Array();
我将 knowledgePoints
定义为:
this.knowledgePoints = 10;
我将 questionCorrect
定义为:
this.questionCorrect = false;
第二次新尝试 使用新 class 作为下面建议的答案 (暂时注释掉,直到我弄清楚如何开始工作):
// package
// {
/*public class Quiz {
//public
var knowledgePoints: int = 10;
//public
var allQuestions: Array = new Array;
//public
var questionCorrect: Boolean = false;
//public
function getTotalScore(): int {
var totalScore: int = 0;
for (var i = 0; i < allQuestions.length; i++) {
totalScore += allQuestions[i].getCalculatedScore();
if (currentModule.allQuestions[i].parent.questionCorrect) {
knowledgePoints++;
} else {
knowledgePoints--;
}
}
debugLog("Total score: " + totalScore);
debugLog(knowledgePoints);
return totalScore;
}
}*/
//}
上面的代码在 Flash 控制台中输出了两个错误:
错误 1. 在 class.
之外使用的属性错误2。无法加载'Int'。
这是一种奇怪的(并且实际上是非 AS3 方式)执行此操作的方式。不要创建一个未命名的闭包,它从谁知道的地方引用奇怪的变量,你应该把它变成一个普通的 AS3 class,类似的东西(在一个名为 Quiz.as 的文件中):
package
{
public class Quiz
{
public var knowledgePoints:int = 10;
public var allQuestions:Array = new Array;
public var questionCorrect:Boolean = false;
public function getTotalScore():int
{
var totalScore:int = 0;
// Your code does not explain how you will that Array.
// It is initially an empty Array of length 0.
for (var i = 0; i < allQuestions.length; i++)
{
totalScore += allQuestions[i].getCalculatedScore();
if (currentModule.allQuestions[i].parent.questionCorrect)
{
knowledgePoints++;
}
else
{
knowledgePoints--;
}
}
// Not sure what it is.
debugLog("Total score: " + totalScore);
debugLog(knowledgePoints);
return totalScore;
}
}
}