patrick3675
09-08-2006, 03:53 PM
I'm (once again) working on a game. It's a bit.. interesting... but it's really just so I can practise some actionscript.
Here's what I need it to do. It's supposed to call up the info about different monsters from the XML file and then sort it into the combobox. Then you can select different monsters from the combobox and whichever you pick will show up in the middle of the screen.
Here's my code:
monstersInfo = new XML;
function updateLoad(root){
for (a=0;a<=root.firstChild.childNodes.length-1;a++){
_root.monsterType.addItem(root.firstChild.childNod es[a].childNodes[0].childNodes,root.firstChild.childNodes[a].childNodes[1].childNodes);
trace(root.firstChild.childNodes[a].childNodes[1].childNodes);
}
}
monsterTypeListener = new Object();
monsterTypeListener.change = function (evt){
_root.stage.gotoAndStop(evt.target.getValue());
}
monsterType.addEventListener("change", monsterTypeListener);
monstersInfo.ignoreWhite = true;
monstersInfo.onLoad = function(success){
if(success){
_root.updateLoad(monstersInfo);
}
}
monstersInfo.load("monstersInfo.xml");
Just so you don't need to find out through the code:
monsterType = the instance for Combobox
monstersInfo = the XML file
And my XML code:
<monsters>
<monster>
<name>Flario</name>
<id>001</id>
</monster>
<monster>
<name>Flaren</name>
<id>002</id>
</monster>
<monster>
<name>Flaroar</name>
<id>003</id>
</monster>
</monsters>
The trace I did in the 'for' code gives me 001,002,003 but when I ask the combobox what data it contains it just gives me an undefined.
Anything I did wrong in there?
Here's what I need it to do. It's supposed to call up the info about different monsters from the XML file and then sort it into the combobox. Then you can select different monsters from the combobox and whichever you pick will show up in the middle of the screen.
Here's my code:
monstersInfo = new XML;
function updateLoad(root){
for (a=0;a<=root.firstChild.childNodes.length-1;a++){
_root.monsterType.addItem(root.firstChild.childNod es[a].childNodes[0].childNodes,root.firstChild.childNodes[a].childNodes[1].childNodes);
trace(root.firstChild.childNodes[a].childNodes[1].childNodes);
}
}
monsterTypeListener = new Object();
monsterTypeListener.change = function (evt){
_root.stage.gotoAndStop(evt.target.getValue());
}
monsterType.addEventListener("change", monsterTypeListener);
monstersInfo.ignoreWhite = true;
monstersInfo.onLoad = function(success){
if(success){
_root.updateLoad(monstersInfo);
}
}
monstersInfo.load("monstersInfo.xml");
Just so you don't need to find out through the code:
monsterType = the instance for Combobox
monstersInfo = the XML file
And my XML code:
<monsters>
<monster>
<name>Flario</name>
<id>001</id>
</monster>
<monster>
<name>Flaren</name>
<id>002</id>
</monster>
<monster>
<name>Flaroar</name>
<id>003</id>
</monster>
</monsters>
The trace I did in the 'for' code gives me 001,002,003 but when I ask the combobox what data it contains it just gives me an undefined.
Anything I did wrong in there?