xml and flash -- .haschildnode?
Posted: Sat Jun 09, 2007 9:13 pm
feyd | Please use
and the xml
what im trying to do is make it where you pick the major mode in a drop down menu, and all the minor modes show up with all the scores and logins relative to them. So far, i only have the drop down menu working, im trying to use the variable i to pull up all the childnodes of the major modes (which would be the minor modes) respecitvely to their parent node, which is pulled up by childnode indexing, but it always comes up undefined. this is the specific part of the code im trying to fix.
am i supposed to use 2d arrays for this? because it seems since ive already pulled up childnodes and use the variable i, it wont let me again, under that index. if so, how would i go about it? im not super familiar with xml or actionscript, hence me being stuck on something like this.
i was also readin up on .haschildNodes. is that something i should be using? ive tried it a few times a few different ways, and i get no results. could anyone explain how to use that in this code if that is what i need to use please?
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ok, ill go ahead and supply my action script and xml first, heres the actionscript
[syntax="actionscript"]// import this so it can be used to set the scope of the combobox listener and the xml onload routine
import mx.utils.Delegate;
// declare variables
var modes:Array;
var update:String;
var dirpath:String;
// create a new color object to associate with the bgcolor movieclip
// set up the XML instance
var newxml:XML = new XML();
// initialize items on stage
_global.style.setStyle("fontFamily", "Verdana");
_global.style.setStyle("fontSize", 11);
// define what should happen when the XML loads
// (read data into update, dirpath, and mode variables)
function onXmlLoaded(success:Boolean) {
if (success) {
// make a handle to the root node in the xml
var mainnode:XMLNode = newxml.firstChild;
update = mainnode.attributes.lastupdate;
dirpath = mainnode.attributes.dir;
// set up an array of all mode nodes
var minorsnodes:Array = newxml.firstChild.firstChild.nextSibling.childNodes;
for (var i:Number = 0; i < minorsnodes.length; i++) {
// for each mode node:
var minornode:XMLNode = minorsnodes[i];
modes.push(
{i:i+1,
pname:minornode.attributes.name,
desc:minornode.childNodes[i].attributes.name
});
//2d array
//xslt html
}
// data is all read and put in the right place -- now setup the screen
// using this data
setup();
} else {
trace('error reading XML');
}
}
function setup() {
// set up chooseperson dropdown
chooseperson.labelField = "pname";
chooseperson.dataProvider = modes;
chooseperson.addEventListener("change", Delegate.create(this, loadScreen));
}
function loadScreen(evt:Object) {
var thisitem:Object = evt.target.selectedItem;
ta9.text = thisitem.desc;
ta2.text = thisitem.desc1;
ta3.text = thisitem.desc2;
ta4.text = thisitem.desc3;
ta5.text = thisitem.score;
ta.vPosition = 0;
}
function init() {
// initialize the mode array
modes = [{pname:"Choose one"}];
names = [{desc:"Select a mode from the dropdown menu"}];
// set up the xml instance to ignore whitespace between tags
newxml.ignoreWhite = true;
// set the scope of the onLoad function to the main timeline, not newxml
newxml.onLoad = Delegate.create(this, onXmlLoaded);
// start the xml loading
newxml.load("1.xml");
}
init();Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<scorelist version="0">
<user>Sciandu</user>
<game name="Harmonic Convergence Deluxe">
<major_mode name="Race">
<minor_mode display_mode="time" name="Asteroid">
<score value="35" login="Sciandu"/>
</minor_mode>
<minor_mode display_mode="time" name="Breach">
<score value="65" login="Sciandu"/>
</minor_mode>
<minor_mode display_mode="time" name="Radioactive Rose">
<score value="24" login="Sciandu"/>
</minor_mode>
<minor_mode display_mode="time" name="Art">
<score value="42" login="Sciandu"/>
<score value="54" login="Mehh"/>
<score value="54" login="tmp1"/>
<score value="91" login="User1"/>
<score value="99" login="Sciandu"/>
</minor_mode>
</major_mode>
<major_mode name="Challenge">
<minor_mode display_mode="number" name="-">
<score value="14" login="Sciandu"/>
</minor_mode>
</major_mode>
<major_mode name="Frenzy">
<minor_mode display_mode="number" name="Camp Fire">
<score value="79" login="Sciandu"/>
</minor_mode>
<minor_mode display_mode="number" name="Art">
<score value="54" login="Sciandu"/>
</minor_mode>
<minor_mode display_mode="number" name="Ritual">
<score value="59" login="tmp1"/>
<score value="53" login="Sciandu"/>
<score value="2" login="Mehh"/>
</minor_mode>
</major_mode>
</game>
</scorelist>
Code: Select all
var minorsnodes:Array = newxml.firstChild.firstChild.nextSibling.childNodes;
for (var i:Number = 0; i < minorsnodes.length; i++) {
// for each mode node:
var minornode:XMLNode = minorsnodes[i];
modes.push(
{i:i+1,
pname:minornode.attributes.name,
desc:minornode.childNodes[i].attributes.name
});
//2d array
//xslt html
}i was also readin up on .haschildNodes. is that something i should be using? ive tried it a few times a few different ways, and i get no results. could anyone explain how to use that in this code if that is what i need to use please?
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]