Here's my xml file
Code:
<?xml version="1.0" encoding="UTF-8"?>
<gameData>
<category id='1' >
<name>Keeping your Credit Clean</name>
<questions>
<question id='1'>
<qText>What is the best way to stay out of debt</qText>
<answers>
<answer id='1' aText="Buy expensive stuff" correct='false' />
<answer id='2' aText="Finance a pizza" correct='false' />
<answer id='3' aText="Don't overspend" correct='true'/>
</answers>
</question>
<question id='2'>
<qText>What would you do for a Klondike bar?</qText>
<answers>
<answer id='1' aText="Three cartwheels and two jumping Jacks" correct='true' />
<answer id='2' aText="Wrestle an alligator" correct='false' />
<answer id='3' aText="Swan dive into a puddle of mud" correct='false'/>
</answers>
</question>
</questions>
</category>
</gameData>
Here's my code...
Code:
// loop thru the XML, populate field on screen with data from XML
var i:int=1;
for each (var cat:XML in gameXML.*){
// set the header of each category (this one only has one category)
this["h"+i].txt.text = cat.name;
trace(cat.name);
for each (var q:XML in cat.questions.*){
trace(" " + q..@id + ") " + q.qText);
var nextQuestion:Object = new Object();
nextQuestion.question = q.qText;
nextQuestion.answers = new Array();
for each (var a:XML in q.answers.*){
trace(" " + a..@id + ") " + a..@aText);
nextQuestion.answers.push(a..@aText);
}
}
i++;
}
Here's my output....
Code:
Keeping your Credit Clean
1123) What is the best way to stay out of debt
1) Buy expensive stuff
2) Finance a pizza
3) Don't overspend
2123) What would you do for a Klondike bar?
1) Three cartwheels and two jumping Jacks
2) Wrestle an alligator
3) Swan dive into a puddle of mud
The only problem is the 1123) and 2123). It should be 1 and 2. Please help