FlashAS基础精典教程(8)
2008-04-02 11:06:09来源:互联网 阅读 ()
答题者所选定的答案将由这个名字来决定,调用一个MC的名字,用的是_name这个属性
所以答题的按钮上面的AS为:
on (release) {
// Trim the prefix "answer" off this clip's name
// 下面使用了String.slice()方法,例如_name为answer0,他将被处理成0,slice的具体语法请查阅AS字典
// 按钮提交什么由该MC的名字决定的,我作个标记 @@ ,记得一会看回来
choice = _name.slice(6, _name.length);
// 和前面的例子相同,最后将答案提交给answer函数处理,但是现在我们是在某一MC里面用外面主时间线的函数了,所以得加上_root
_root.answer(choice);
}
最后,Options>> Linkage,标识名:answerTemplate,制作模版的工作就完成了
下面将是放在第一帧的程式主体,可要打起精神来了:
// Stop the movie
stop();
// Init main timeline variables
var displayTotal; // Text field for user's final score
var totalCorrect = 0; // Number of questions answered correctly
// Array containing the user's guesses 记录作答答案的数组
var userAnswers = new Array();
// Number of the question the user is on 记录正在作答中题目的编号
// 要注意的是,他是由0开始的,第一题的编号是0,因为我们要用到数组,数组的第一个编号是0,所以这里我们也用0
var currentQuestion = 0;
// The Question constructor
// 以下是新类型对象question的构造函数,包含三个属性:正确答案,题目正文,各个选项
function Question (correctAnswer, questionText, answers) {
this.correctAnswer = correctAnswer;
this.questionText = questionText;
this.answers = answers;
}
// Import the source file containing our array of question objects
// 咦?应该是输入各条题目的数据先啊,放哪去了?因为嘛,数据输入是个和编程无关的过程,为了让代码更优雅,这些繁琐的东西扔别地方去了,AS太长,会使查阅相当麻烦,分开存放也是好习惯!
// #include是引用外部AS命令,能够将AS分开储存于各个后缀名为AS的文档中,输入题目的代码就是放到了questionsArray.as中(记得和FLA放在同一目录下喔)
#include "questionsArray.as"
//// 我改变了一下教程的结构,把questionsArray.as的内容也插入进来了,因为跳过这段的话,看起来会有疑问
//// 以下内容系存放questionsArray.as中的
// 输入数据其实是建立对象
// MOOCK用一个数组还存放这些对象,这样对象才更易于管理
// 不要被括号给弄昏了,输入对象参数的中间更有中括号,是因为输入题目的参数“各个选项”是个数组
// 因为是存放于数组中,每个对象之间记得应有逗号分隔
// 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就是第一条题目对象的问题属性
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇: 使用钢笔工具绘制曲线路径
下一篇: 拖拽动作连同碰撞动作周详讲解
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
