AS2答案输入测验

时间:2013-01-28 22:24:07

标签: arrays syntax-error actionscript-2

  answer = new Array();
answer[0] = "1997";
answer[1] = "1941";
question = new Array();
question[0] = "What ...?";
question[1] = "Why ...?";

question_txt.text = question;
enter1.onRelease = function()
{
    if (answer_input.text == answer)
    {
        answer++;
        question++;
        question_txt.text = question;
    }
    else
    {
        answer_input.text = "Incorrect";
    }
};

有2个文本框和一个按钮 TextBox1 = question_txt - 用于显示问题且类型为[Dynamic] textBox2 = answer_input - 允许用户尝试回答问题

答案和问题的价值刚刚弥补,不介意。

那么为什么它不起作用?

2 个答案:

答案 0 :(得分:1)

好吧,我不是专家,但看起来question是一个数组,你试图将question_txt.text设置为question,这实际上是整个数组。然后,您尝试向answerquestion数组添加1,这将无效。

您真正要做的是访问这些数组的元素,为此,您需要将索引传递给您的数组。 (question [0] =“问题数组中的第一个元素”)所以你需要的是一个跟踪你当前正在使用的这些数组的索引的变量。像这样......

answer = new Array();
answer[0] = "1997";
answer[1] = "1941";
question = new Array();
question[0] = "What ...?";
question[1] = "Why ...?";

qanda_number = 0;


question_txt.text = question[qanda_number];
enter1.onRelease = function()
{
    if (answer_input.text == answer[qanda_number)
    {
        qanda_number++;
        question_txt.text = question[qanda_number];
        // You probably want to empty out your answer textfield, too.
    }
    else
    {
        answer_input.text = "Incorrect";
    }
};

答案 1 :(得分:0)

answer = new Array(); //Create a list of answers.
answer[0] = "Insert Answer"; //Answer is ...
answer[1] = "Insert Answer"; //Answer1 is ...
question = new Array(); //Create a list of questions.
question[0] = "Insert Question"; //Question is ...
question[1] = "Insert Question"; //Question1 is ..
index = 0; //Create an index number to keep answers and questions in order

onEnterFrame = function () //Constantly...
{
    question_txt.text = question[index] //Make the question in tune with the index num
};



button.onRelease = function() //On the release of a button...
{
    if (answer_input.text == answer[index]) //if the User's guess is correct - proceed
    {
        index++; //Move up in the Index
        answer_input.text = ""; //Reset the User's guess
    }
    else
    {
        answer_input.text = "Incorrect"; //Display Incorrect over the User's guess
    }
};