Code Snippets   | [Bill's Home]

Reading XML from Flash (Pt. 3)

Next we can add actions on the green buttons, so that they set variables when they are pressed. This can be achieved with the following action code:

on (press, release) {
 ../:question_select="q1";
}

 

which sets the questions_select variable on the parent movie. Each of the buttons then set the question_select variable. Next we can add two new functions to the main action script. The get_question() function sets the question for the array of questions, and the answered() function is called when an answer is select. These are given next:

function get_question()
{
 i = random(no_q-1);
 question_text = correct;
 question.title = question_titles[i];
 question.q1 = question_q1[i];
 question.q2 = question_q2[i];
 question.q3 = question_q3[i];
 question.q4 = question_q4[i];
}

function answered()
{

 if (question_select == question_ans[i]) {
  correct++;
 }
 question_text = correct;
 question_select = "";
}

These functions can be called from an action script with:

if (question_select<>"")
{
 answered();
 get_question();
}

which selects if an answer has been selected. If it has the answered() function is called, followed by the get_question() function. The new movie is:

The background still looks a bit boring, thus we can quickly insert a clip-art image, and set an alpha value of 80%: