【发布时间】:2014-03-20 08:55:19
【问题描述】:
谁能帮助我了解如何在随机加载问题的问答游戏中包含图片?我已经有一个游戏,其中问题和答案被添加到数组中。如果用户在文本字段中输入完他的答案,他将单击一个按钮,游戏将显示答案是否正确。如果所有问题都被加载,游戏将自动结束。它工作得很好,但我想展示一些图片和问题。例如,有一个问题:“这是什么鸟?”还有一张鸟的照片和问题。我将如何实现这一点?此外,不只是图片,我还可以包含 swf 或影片剪辑吗?我认为动画比图片更酷。但如果没有,图片是可以的。这是代码..我非常感谢任何帮助。
var quizModel:Array = [{q:"1+1 = ?", a:"2"}, {q:"5+5 = ?", a:"10"}, {q:"2+2 = ?", a:"4"}, {q:"6+6 = ?", a:"12"},{q:"8-7 = ?",a:"1"}];
var user_ans:Array = new Array();
var newQuizModel:Array = shuffleArray(quizModel);
function shuffleArray(arr:Array):Array
{
var l:Number = arr.length - 1;
for (var it:uint = 0; it<l; it++)
{
var r:int = Math.round(Math.random() * l);
var tmp:Object = arr[it];
arr[it] = arr[r];
arr[r] = tmp;
}
return arr;
}
var index:int = 0;
questions_txt.text = newQuizModel[index]["q"];
submit.label = "Submit"; //This is a button I made from the” windows->component” that has a label “Submit”. If clicked, it will check if the answer is correct or not
submit.addEventListener(MouseEvent.CLICK,yow);
function yow (event:MouseEvent):void{ //Runs if the Submit button is clicked
if (userAnswer.text == newQuizModel[index]["a"])
{
answers_txt.text = "Your answer is correct!";
}
else
{
answers_txt.text = "Your answer is wrong";
}
index++;
if(index == quizModel.length){ //Runs if all of the questions in the array loads
Over.text = "It's Over!";
index--;
submit.visible=false;
questions_txt.visible=false;
userAnswer.visible=false;
}
showQuiz(index);
}
function showQuiz(idx:int):void
{
questions_txt.text = "Question: " + newQuizModel[idx]["q"];
}
showQuiz(index);
【问题讨论】:
标签: actionscript-3