Hi Folks
For eg like [ [ [Electronics],[TV, Plasma, Digital]], [[Jewellery],[Beads, Pearls, Chains] ] ]
My objective is to have a list box for Top level nodes (Electronics, Jewellery) and then when you click on the Top level nodes another list box populates with Child nodes of the Selected node
Code attached below gets me the data into 2 different arrays. But I dont know how to associate the Top level node to that of the child node
var myXML = new XML(); //new
var main_menu_array:Array = new Array();
var submenu_array:Array = new Array();
myXML.ignoreWhite = true;
myXML.onLoad = function(success) {
if (success) {
var l = this.childNodes.length // Get the Total number of Top Level Nodes
for (var i=0; i<l; i++){ // Loop thru the top level nodes
t = this.childNodes*.childNodes.length ; // Get the Child objects of the Top Level Nodes
trace("top level>> " + this.childNodes*.attributes.label); // Gets Electronics and Jewellery
main_menu_array.push({Label:this.childNodes*.attributes.label});
for (var j=0; j<t; j++){ // Loop thru the Child Objects submenu_array.push({Label:this.childNodes*.childNodes[j].attributes.label,Url:this.childNodes*.childNodes[j].attributes.url,Description:this.childNodes*.childNodes[j].attributes.description});
}
}
main_menu_array.sortOn("Label");
submenu_array.sortOn("Label", Array.CASEINSENSITIVE); // sort on result array on step_value
mainMenu_listBox.setDataProvider(main_menu_array); // Add Top Level Items to the List Box
mainMenu_listBox.setChangeHandler("setSizes");
} else {
trace(“ERROR! XML not found.”);
}
};
myXML.load(“menu.xml”);
mainMenu_listBox.setChangeHandler(“setSizes”);
function setSizes(component)
{
trace(“sizeArray”);
sizeArray = mainMenu_listBox.getSelectedItems();
for (i = 0 ; i < sizeArray.length ; i++)
trace("Item " + (i + 1) + " = " + sizeArray*.label);
}
<?xml version=“1.0” encoding=“iso-8859-1”?>
<node label =“Electronics”>
<node label=“TV” url=“app/elec.swf” isBranch = “true” description = “TV Description goes here”/>
<node label=“Plasma” url=“app/plasma.swf” isBranch = “true” description = “PLASMA Description goes here”/>
<node label=“Digital Cam” url=“app/digi.swf” isBranch = “true” description = “Digital Cam Description goes here”/>
</node>
<node label =“Jewellery”>
<node label=“Beads” url=“app/beads.swf” isBranch = “true” description = “Beads Description goes here”/>
<node label=“Pearls” url=“app/pearls.swf” isBranch = “true” description = “Pearls Description goes here”/>
<node label=“Chains” url=“app/chains.swf” isBranch = “true” description = “Chains Description goes here”/>
</node>
<node label =“Audio”>
<node label=“Speakers” url=“app/beads.swf” isBranch = “true” description = “Beads Description goes here”/>
<node label=“Base” url=“app/pearls.swf” isBranch = “true” description = “Pearls Description goes here”/>
<node label=“Controller” url=“app/chains.swf” isBranch = “true” description = “Chains Description goes here”/>
</node>
Thanks