【问题标题】:AS3: Include pictures in a Quiz Game which loads questions in randomAS3:在随机加载问题的问答游戏中包含图片
【发布时间】: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


    【解决方案1】:

    您在使用 Flash 工作吗?如果在 Flash 中,您可以将图片或影片剪辑放入 fla 的库中,然后在显示每个问题时实例化它们。

    例如,在他们的属性对话框中给他们一个 Export for Actionscript 类名称。然后将类名添加到每个问题的数据中,如下所示:

    {q:"1+1 = ?", a:"2", className: "two_birds"}
    

    接下来,从库中实例化符号并将其添加到您的显示列表中,如下所示:

    var classRef:Class = getDefinitionByName(newQuizModel[idx]["className"]) as Class;
    var displayObj:Object = new classRef();
    addChild(displayObj);
    displayObj.x=20;
    displayObj.y=20;
    

    或者类似的东西。我会让你去解决细节。

    【讨论】:

    • 感谢您的回复..是的..我正在使用 flash..我会立即尝试..非常感谢..如果我有错误,我会与您联系虽然..
    • 很高兴为您提供帮助!如果您觉得有帮助,请记得采纳答案。
    猜你喜欢
    • 1970-01-01
    • 2015-09-18
    • 2017-06-02
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 1970-01-01
    相关资源
    最近更新 更多