【问题标题】:keeping track of a series of simple multiple choice web form answers跟踪一系列简单的多项选择网络表单答案
【发布时间】:2017-10-09 09:39:29
【问题描述】:

这是我正在尝试使用的代码,这似乎是合乎逻辑的。但似乎不起作用。

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。无法加载“Int”。

【问题讨论】:

    标签: actionscript actionscript-2


    【解决方案1】:

    这是一种奇怪的(实际上是非 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;
            }
        }
    }
    

    【讨论】:

    • 谢谢!我会尝试这种方法。你的评论是什么'//你的代码没有解释你将如何处理这个数组。'?
    • 使用 'debugLog' 我试图打印当前总数
    • @X-RaySpecs 您的某些代码可能对您有意义,因为您了解全局。所以我把 cmets 说清楚了。
    • 啊,好的。我得到 2 个错误:/ 一个带有“公共类测验”行的错误 - 状态“在类之外使用的属性”和“无法加载类或接口 'int'。”
    • @X-RaySpecs 这意味着您使用的是 AS1/2 而不是 AS3。
    猜你喜欢
    • 1970-01-01
    • 2011-08-14
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    相关资源
    最近更新 更多