Hi all,
Need help with this. Just a simple multiple choice quiz: questions and possible answers are in a xml-file, like
<?xml version=“1.0” encoding=“iso-8859-1”?>
<quiz>
<q1>
<text>How old is the oldest tree?</text>
<correct>3</correct>
<a1>50</a1>
<a2>150</a2>
<a3>250</a3>
<a4>350</a4>
</q1>
<q2>
<text>What is the formula for a cicrle?</text>
<correct>1</correct>
<a1>2pir</a1>
<a2>e=mc</a2>
<a3>x=y*(3.14/34)</a3>
<a4>3.50</a4>
</q2>
</quiz>
IN my flash movie i got the following AS:
//load the dyn data and put it arrays questions, correct answer and answers
quizContent = new XML ();
quizContent.ignoreWhite = true;
quizContent.onLoad = function (success) {
//test if the data has been loaded succesfully
if (success) {
trace ("Qiuz.xml succesfully loaded.");
processQuiz (quizContent);
} else {
trace ("Something went wrong");
}
};
quizContent.load ("quiz.xml");
//what to do with all the xml data
//create an array for each questions
// Create an array to contain each question's correct answer.
// create an multiarray for a 4-part answers
processQuiz = function (quiz_xml) {
quiz = new Object ();
quiz.questions = new Array();
quiz.correct = new Array();
quiz.multiAnswers = new Array();
//parsing the xml file
rootXML = quiz_xml.firstChild;
for (var n = 0; n<rootXML.childNodes.length; n++) {
trace ("Push: "+rootXML.childNodes[n].firstChild.firstChild.nodeValue);
quiz.questions.push(rootXML.childNodes[n].firstChild.firstChild.nodeValue);
for (var j = 0; j<rootXML.childNodes[n].childNodes.length; j++) {
trace (rootXML.childNodes[n].childNodes[j].firstChild.nodeValue);
}
quiz.correct.push(rootXML.childNodes[n].childNodes[1].firstChild.nodeValue)
//now we want to store all answers for each question in an array called answers
//store all answers
//myArray* = new Array(4);
quiz.answers[n] = new Array();
for (a=2; a<6; a++) {
//store each answer
quiz.answers[n].push(rootXML.childNodes[n].childNodes[a].firstChild.nodeValue);
trace("The answer is: "+rootXML.childNodes[n].childNodes[a].firstChild.nodeValue);
}
quiz.multiAnswers.push(quiz.answers[n]);
trace("huh "+quiz.answers[n]);
}
trace ("First question: "+quiz.questions[0]);
trace ("Correct answers " +quiz.correct);
trace ("All answers " +quiz.multiAnswers);
};
Furthermore, i think i understand the dimensional array. In the end i want, based on the xml file:
quiz.multiAnswers = [[50,150,250,350],[1,2pir,e=mc,x=y*,3.50]]
So i can put the array content in dyn. textfield by adressing them like quiz.multiAnsers[0][1] gives me “150”, right?
thnks in advanced.