-
1. Re: parse xml
Harry Kunz Mar 9, 2010 6:40 AM (in response to decpariem)You have to first get the root node (top level "menu" node) by getting the firstChild of your XML object like this:
var cNode:XMLNode = oXml.firstChild;
var nChildren:Number = cNode.childNodes.length;
You were looping at the root that's why you only had one node returned. Use nChildren as delimiter to loop through the sibling nodes under first menu node. Can you give the exact XML content? Because if it only looks like that, you could simply access the leaf node by using firstChild.firstChild.firstChild.fiirstChild.firstChild.nodeValue. By the way, it's a bad idea to have children nodes named the same as their parent nodes.
-
-
-
4. Re: parse xml
Mohammed Kayyali Mar 9, 2010 9:12 AM (in response to decpariem)here we are:
//Vars var idArr:Array = new Array(); var subIDArr:Array = new Array(); //XML var menus:XML = new XML(); menus.load("menu.xml"); menus.ignoreWhite = true; menus.onLoad = function(success) { if (success) { var menuData = menus.firstChild.childNodes; for (i = 0; i < menuData.length; i++) { subNodes = menuData[i].childNodes; if (menuData[i].nodeName == "vid") { //Get ID idArr.push(menuData[i].attributes.id); //loop for subs for (j = 0; j <= subNodes.length; j++) { if (subNodes[j].nodeName == "submenu") { subIDArr.push(subNodes[j].attributes.id); } } } } } else { trace("Error on loading xml"); } trace("Main ID: " + idArr); trace("Main ID: " + subIDArr); };but my opinion for you to change the attribute name (id) to anything else like ( Id, ID ) as id is a reserved for use by the ActionScript language.
-
-
6. Re: parse xml
Mohammed Kayyali Mar 9, 2010 9:58 AM (in response to decpariem)in your example, we can create new movieclip first then load on it the attached menu, so add this line:
this.createEmptyMovieClip("cont",0);then inside your for loop this:
cont.attachMovie("subSuperButton","subButton" + j,j,{_x:20, _y:20}); cont["subButton" + j].id_txt.text = subNodes[j].attributes.id; cont["subButton" + j].linkPath = subNodes[j].attributes.link; cont["subButton" + j]._y = j * 30; cont["subButton" + j].onRelease = function() { trace("URL Path: " + this.linkPath); }; -
7. Re: parse xml
Mohammed Kayyali Mar 9, 2010 10:15 AM (in response to decpariem)all code if you wish is below:
//create empty movieclip to load inside it the submenu this.createEmptyMovieClip("cont", 0); //XML var menus:XML = new XML(); menus.load("menu.xml"); menus.ignoreWhite = true; menus.onLoad = function(success) { if (success) { var menuData = menus.firstChild.childNodes[2].childNodes; for (j = 0; j <= menuData.length; j++) { if (menuData[j].nodeName == "submenu") { cont.attachMovie("subSuperButton","subButton" + j,j,{_x:20, _y:20}); cont["subButton" + j].id_txt.text = menuData[j].attributes.id; cont["subButton" + j].linkPath = menuData[j].attributes.link; cont["subButton" + j]._y = j * 30; cont["subButton" + j].onRelease = function() { trace(this.linkPath); }; } } } else { trace("Error on loading xml"); } };i hope this to help you




