// Place this answer clip in line below the question. // 设定MC的位置,第一个高度为70,之后顺序加15 questionClip["answer" + j]._y += 70 + (j * 15); questionClip["answer" + j]._x -= 100; // Set the text field in the answer clip to the appropriate // element of this question's answer array. // 下面语句的:questionClip["answer" + j]可不是指数组,j=0的时候,它代表questionClip.answer0,具体解释可见上一章。 // 这句语句的作用是把questionsArray[currentQuestion]这个对象数组里面的answers[j]数组,输入到对应的选项MC的answerText文本框中,就是该选项的内容 questionClip["answer" + j].answerText = questionsArray[currentQuestion].answers[j]; } //生成选项的循环结束 } // Function to register the user's answers // 以下是记录答题者答案的函数,记录在数组userAnswers中,和上一例同 // 每一个选项如果被选都会调用此函数,并用参数choice传来作答的答案 function answer (choice) { userAnswers.push(choice); // 判断是否题目全部完成,是的话清楚掉题目MC,并跳转到quizEnd帧 if (currentQuestion + 1 == questionsArray.length) { questionClip.removeMovieClip(); gotoAndStop ("quizEnd"); } else { // 在这里改变题目的编号,然后调用makeQuestion函数再次生成新的题目 currentQuestion++; makeQuestion(currentQuestion); } } // Function to tally the user's score // 改题的函数 function gradeUser() { // Count how many questions the user answered correctly for (var j = 0; j < questionsArray.length; j++) { // 将答题数组userAnswers[j]与问题数组questionsArray[j]的属性correctAnswer逐个比较 if (userAnswers[j] == questionsArray[j].correctAnswer) { totalCorrect++; } } // Show the user's score in an onscreen text field // 显示答对与题目数比 displayTotal = totalCorrect + "/" + questionsArray.length; }