// 因为是存放于数组中,每个对象之间记得应有逗号分隔 // Remember to place a comma after each object // in the array except the last questionsArray = [new Question (2, "Which version of Flash first introduced movie clips?", ["version 1", "version 2", "version 3", "version 4", "version 5", "version 6"]), new Question (2, "When was Action formally declared a ing language?", ["version 3", "version 4", "version 5"]), new Question (1, "Are regular expressions supported by Flash 5 Action?", ["yes", "no"]), new Question (0, "Which sound format offers the best compression?", ["mp3","aiff", "wav"]), new Question (1, "True or False: The post-increment operator (++) returns the value of its operand + 1.", ["true", "false"]), new Question (3, "Action is based on...", ["Java", "Java", "C++", "ECMA-262", "Perl"])]; //// 离开questionsArray.as部分,我们继续 // Begin the quiz 出题目!调用makeQuestion函数来完成,我们只需要给这个函数一个参数:题目的编号,函数就会按编号提取数据,结合我们刚才做的模版生成题目。 makeQuestion(currentQuestion); // Function to render each question to the screen // 下面就是makeQuestion函数 function makeQuestion (currentQuestion) { // Clear the Stage of the last question //这句是清理上一题生成的MC,这句从第二题开始生效,questionClip就是题目的MC名,MC从哪来的?看下面就知道了 questionClip.removeMovieClip(); // Create and place the main question clip // 利用模版questionTemplate生成一个叫questionClip的MC,这个MC就是我们的问题 attachMovie("questionTemplate", "questionClip", 0);
// 设定MC的位置 questionClip._x = 277; questionClip._y = 205; // 把题目编号输入MC的qNum文本框中 questionClip.qNum = currentQuestion + 1; // questionsArray[currentQuestion]就是数组questionsArray里的第currentQuestion个对象,例如currentQuestion是0,那么就是我们的第一条题目 // questionsArray�.questionText就是第一条题目对象的问题属性 // 然后问题输入MC的qText文本框中 questionClip.qText = questionsArray[currentQuestion].questionText; // Create the individual answer clips in the question clip // 以下循环将结合选项模版生成这一条题目的各个选项的MC // questionsArray[currentQuestion].answers记得吗?选项这个属性可是个数组,所以我们把它的长度作为循环的次数,这个数组有多大,我们就生成多少个选项 for (var j = 0; j < questionsArray[currentQuestion].answers.length; j++) { // Attach our linked answerTemplate clip from the Library. // It contains a generalized button and a text field for the question. // 用answerTemplate做模版生成MC,MC名为"answer" + j ,即第一个选项MC名为answer0,第二个为answer1,选项的名字可是关系到按钮选什么的,如果你忘了,看看上面有 @@ 标记的地方 // 同时它们的深度为j,每次不同 // 但和上面不同的是,我们要把选项MC生成到题目MC里,这样我们清除题目MC的同时也清除了选项 // 所以写成questionClip.attachMovie questionClip.attachMovie("answerTemplate", "answer" + j, j);