lorcanO33
lorcanO33

Reputation: 32

AS2 Answer Input Quiz

  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";
    }
};

There's 2 text boxes and a button TextBox1 = question_txt - which is to display the question and is of type [Dynamic] textBox2 = answer_input - which is to allow users to attempt to answer the question

The values of the answers and questions are just made up, don't mind them.

So why isn't it working?

Upvotes: 1

Views: 538

Answers (2)

lorcanO33
lorcanO33

Reputation: 32

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
    }
};

Upvotes: 0

Todd Kerpelman
Todd Kerpelman

Reputation: 17523

Well, I'm no as2 expert, but it looks like question is an array, and you're trying to set question_txt.text to question, which is really the entire array. And then later, you're trying to add 1 to the answer and question arrays, which won't work.

What you're really looking to do is access elements of these arrays, and to do that, you need to pass an index to your array. (question[0] = "The first element in the question array") So what you need is a variable that keeps track of the index of these arrays you're currently using. Something like this...

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";
    }
};

Upvotes: 1

Related Questions