跟踪一系列简单的多选网页形式答案

时间:2017-05-10 16:00:35

标签: actionscript actionscript-2

这是我尝试使用的代码,这似乎是合乎逻辑的。但似乎并没有起作用。

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;
 }
}*/
//}

以上代码在Flash控制台中输出两个错误:

错误1.在课堂外使用的属性。

错误2.&#39; Int&#39;无法加载。

1 个答案:

答案 0 :(得分:1)

这是一种奇怪的(实际上是非AS3方式)方式。而不是创建一个未命名的闭包,它引用奇怪的变量来自who-know where,你应该把它变成一个普通的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;
        }
    }
}