Actionscript多维测验引擎

时间:2013-01-29 20:45:03

标签: arrays variables multidimensional-array actionscript-2

这是我的测验应用程序的引擎,但我注意到我无法为一个问题分配多个答案而不会完全搞乱。

answer[0] = ["Green", "Blue", "Red"]
answer[0] = "Green" or "Blue" "Red"

我开始研究多维数组,但我无法让它工作。 请帮忙。 这是我的引擎:

answer = new Array()
answer[0] = "Green"; //THIS IS LIMITED as there are more answers like red or blue
answer[1] = "2"; //Only one answer
question = new Array();
question[0] = "What colours are in the Rainbow";
question[1] = "1+1";
index = 0;

onEnterFrame = function ()
{
    question_txt.text = question[index];
};



enter1.onRelease = function()
{
    if (answer_input.text == answer[index])
    {
        index++;
        answer_input.text = "";
    }
    else
    {
        answer_input.text = "Incorrect";
    }
};

1 个答案:

答案 0 :(得分:1)

answer[0] = ["Green", "Blue", "Red"];

..那么条件应如下所示:

enter1.onRelease = function(){

  var good=false;
  for(var i=0;i<answer[index].length;i++){
    if(answer[index][i]==answer_input.text){
      good=true;
    }
  }

  if(good){
    index++;
    answer_input.text = "";
  else{
    ...
  }