这是我尝试使用的代码,这似乎是合乎逻辑的。但似乎不起作用。
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;
按照下面的答案建议对新类进行的第二次新尝试(暂时注释掉,直到我弄清楚如何开始工作(:
// 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;
}
}*/
//}
上面的代码在闪存控制台中输出两个错误:
错误 1。在类外部使用的属性。
错误 2。无法加载"Int"。
这是一种
奇怪的(实际上是非AS3方式(的方法。与其创建一个未命名的闭包来引用来自谁知道在哪里的奇怪变量,不如让它成为一个普通的 AS3 类,类似于这样(在名为 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;
}
}
}