Code Snippets   | [Bill's Home]

Reading XML from Flash (Pt. 4)

After this we need to determine the maximum number of questions to ask, and the user should be shown their score after it. The get_question() and the answered() functions can be modified with:

function get_question () {
i = random(no_q);
question_text = correct;

question.title = (correct+incorrect+1) + "." + question_titles[i];
question.q1 = question_q1[i];
question.q2 = question_q2[i];
question.q3 = question_q3[i];
question.q4 = question_q4[i];
debug = "Question "+(i+1)+" from "+no_q+"[Level:"+question_level[i]+"]";
}
function answered () {
if (question_select == question_ans[i]) {
correct++;
}
else incorrect++;
question_text = correct;
question_select = "";
if ((correct+incorrect)==no_questions_taken)
{
final_score=correct + " out of " + no_questions_taken;
gotoAndPlay ( 8 );
}

}

The following gives the updated version:

An example of test part has been added, which shows the score to the user. If you have a stand-alone Shockwave Player the click here.

Another, more practical tutorial is given next:

Click here to expand it.