| bolance |
2007-06-29 10:43 |
var currentQuestion = 0; 6#VG,'e3 // The Question constructor eA9U|&o // 以下是新类型对象question的构造函数,包含三个属性:正确答案,题目正文,各个选项 g/,fjM_ function Question (correctAnswer, questionText, answers) { 7><n e|% this.correctAnswer = correctAnswer; wJ-G7V,) this.questionText = questionText; 86O"w*9 this.answers = answers; (;YO]U4 } n's3!HQY[ // Import the source file containing our array of question objects
3U=q3{%1 // 咦?应该是输入各条题目的数据先啊,放哪去了?因为嘛,数据输入是个与编程无关的过程,为了让代码更优雅,这些繁琐的东西扔别地方去了,AS太长,会使查阅相当麻烦,分开存放也是好习惯! YAnt}]u!" // #include是引用外部AS命令,可以将AS分开储存于各个后缀名为AS的文件中,输入题目的代码就是放到了questionsArray.as中(记得和FLA放在同一目录下喔) l!e8=QlJ #include "questionsArray.as" 4S|! iOY //// 我改变了一下教程的结构,把questionsArray.as的内容也插入进来了,因为跳过这段的话,看起来会有疑问 fVv#| //// 以下内容系存放questionsArray.as中的 8=ubMqr[ // 输入数据其实是建立对象 )l*H$8 // MOOCK用一个数组还存放这些对象,这样对象才更易于管理 nW
+rJ // 不要被括号给弄昏了,输入对象参数的中间还有中括号,是因为输入题目的参数“各个选项”是一个数组 Pi::cf>3 // 因为是存放于数组中,每个对象之间记得应有逗号分隔 Nk=F.fp|/ // Remember to place a comma after each object >|SB]'C| // in the array except the last E
}|g3 questionsArray = [new Question (2, m3XL;1y:a "Which version of Flash first introduced movie clips?", uHBX}WH
["version 1", "version 2", "version 3", B5Rm z& "version 4", "version 5", "version 6"]), R[
S*ON new Question (2, w_G/[R3 "When was Action formally declared a ing language?", iQ*JU2;7t ["version 3", "version 4", "version 5"]), D
h ]+HF new Question (1, a{Y:hrd:Z "Are regular expressions supported by Flash 5 Action?", 4?M=?K0 ["yes", "no"]), ,HS\
(Z new Question (0, 5b9_6L6 "Which sound format offers the best compression?", |Z6rP- ["mp3","aiff", "wav"]), 7M}T^LC new Question (1, xXH%7%W'f "True or False: The post-increment operator (++) returns the 8<3J!X+ value of its operand + 1.", btw_k+Fh ["true", "false"]), iKV;>gF,)v new Question (3, B$g!4C
`g "Action is based on...", N::_JH?^= ["Java", "Java", "C++", "ECMA-262", "Perl"])]; 9?gLi!rd //// 离开questionsArray.as部分,我们继续 |U1X~\"" // Begin the quiz 出题目!调用makeQuestion函数来完成,我们只需要给这个函数一个参数:题目的编号,函数就会按编号提取数据,结合我们刚才做的模版生成题目。 4 *He<2g makeQuestion(currentQuestion); ^SxB b,\ // Function to render each question to the screen ;z#D%#Ztq // 下面就是makeQuestion函数 o;
6\ function makeQuestion (currentQuestion) { $ePAsJ // Clear the Stage of the last question C5i]n? )S //这句是清理上一题生成的MC,这句从第二题开始生效,questionClip就是题目的MC名,MC从哪来的?看下面就知道了 $q
DH questionClip.removeMovieClip(); ,f$A5RN // Create and place the main question clip ~Ht[kO // 利用模版questionTemplate生成一个叫questionClip的MC,这个MC就是我们的问题 vkE6e6,Qc attachMovie("questionTemplate", "questionClip", 0); gTW(2?xYf // 设定MC的位置 eN>=x40 questionClip._x = 277; h_?D%b~5 questionClip._y = 205; o?$D09j;; // 把题目编号输入MC的qNum文本框中
?.|qRzWL questionClip.qNum = currentQuestion + 1;
(8@._ // questionsArray[currentQuestion]就是数组questionsArray里的第currentQuestion个对象,例如currentQuestion是0,那么就是我们的第一条题目 Cf<i" // questionsArray.questionText就是第一条题目对象的问题属性 j
?/T7a^ // 然后问题输入MC的qText文本框中 :uZcN questionClip.qText = questionsArray[currentQuestion].questionText; kxWf1hIz0 // Create the individual answer clips in the question clip _R]la&^2F\ // 以下循环将结合选项模版生成这一条题目的各个选项的MC |
|