1
  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 - 允许用户尝试回答问题

答案和问题的价值只是虚构的,不要介意。

那么为什么它不起作用呢?

4

2 回答 2

1

好吧,我不是 as2 专家,但它看起来像是question一个数组,而您正试图设置question_txt.textquestion,这实际上是整个数组。稍后,您尝试将 1 添加到answerandquestion数组中,但这是行不通的。

您真正要做的是访问这些数组的元素,为此,您需要将索引传递给您的数组。(question[0] = "The first element in the question array") 所以你需要一个变量来跟踪你当前使用的这些数组的索引。像这样的东西...

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";
    }
};
于 2013-01-28T22:38:56.650 回答
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
    }
};
于 2013-01-29T18:54:17.580 回答