Groups | Blog | Home
all groups > flash actionscript > may 2007 >

flash actionscript : trouble loading XML into an array


jawwinker
5/17/2007 11:21:02 PM
Hello,

So I have been banging my head angainst the wall on this one. I'm basically
trying to read an XML file, that will then bestored in an array. I got the
first level of the XML heirarchy to work, but I cannot get the second. I
believe that it all stems from the issue of being able to name the object what
I want to...

ex: menuArray[a].submenu[b]

This would obviously be the best name, so the name itself will tell me what
menu the submenu belongs to. Does anyone have a work-a-round for this type of
situation? Any insight is greatly appreciated.

Thanks
Steve

xmlMenu = new XML();
xmlMenu.ignoreWhite = true;
xmlMenu.load("xml/menu.xml");
menuArray = new Array();

//===== ON XML LOAD ==============================
xmlMenu.onLoad = function(success){
if(success){
xmlItems = this.firstChild.childNodes;
parseBtns(xmlItems);
}
}

//======== SET POPUP VALUES ===============================
function parseBtns (xmlref){
for(a = 0; a < xmlref.length; a++){
menuArray[a] = new Object();
menuArray[a].name = xmlref[a].attributes.name;
menuArray[a].link = xmlref[a].attributes.link;
menuArray[a].visibility = "visible";

for(b = 0; b < xmlref[a].childNodes.length; b++){
menuArray[a].submenu[b]. = new Object();
menuArray[a].submenu[b].name = xmlref[a].childNodes[b].attributes.name;
menuArray[a].submenu[b].link = xmlref[a].childNodes[b].attributes.link;
menuArray[a].submenu[b].visibility = "notvisible";

if menuArray[a].submenu[b] != null){
trace ("object exists");
} else {
trace ("object doesn't exist")
}
}
}
};
kglad
5/17/2007 11:26:51 PM
jawwinker
5/17/2007 11:33:50 PM
Genius! That totally worked! Thanks kglad!

kglad
5/18/2007 3:55:34 AM
AddThis Social Bookmark Button