- Edited
Hey guys. I'm trying to build a multi-level XML drop down menu. The point is to retrieve all the data from an XML file, parse it in AS3.0 and do the magic. Some of my XML nodes have child nodes but others don't. The parent nodes will be top level menu items, while the child nodes will be the sub level menu items i.e these will drop down. My plan is to load the top level parent nodes (which is working fine so far) and then check whether this node has children, and if it does then I want to load those nodes and construct the drop down menu. But I'm having trouble to get past the top level parent nodes... anyway, here's my XML and AS3 code so far:
<menu>
<item text="Home" link="www.google.com">
</item>
<item text="About">
<sub text="About Us" link="www.facebook.com"></sub>
<sub text="Biography" link="www.google.com"></sub>
</item>
<item text="Portfolio">
<sub text="Flash" link="www.developphp.com"></sub>
<sub text="PHP/MySQL" link="www.php.net"></sub>
<sub text="Print Design" link="www.cssmania.com"></sub>
<sub text="Community" link="www.lebgeeks.com"></sub>
</item>
<item text="Contact Us" link="www.facebook.com">
</item>
</menu>
and here's part of my AS3 code
private function xmlLoaded(e:Event):void
{
xmlLoader.removeEventListener(Event.COMPLETE, xmlLoaded);
xmlData = new XML(e.target.data);
menuList = new XMLList(xmlData.item);
parseXML();
}
private function parseXML():void
{
menuItems = new Array();
for (var i:uint = 0; i < menuList.length(); i++)
{
var item:MenuItem = new MenuItem();
item.x = (item.width + offset) * i;
item.y = 10;
item.textBox.text = menuList[i].@text;
item.textBox.mouseEnabled = false;
item.link = menuList[i].@link;
item.buttonMode = true;
menuItems.push(item);
addChild(item);
checkForChildren(menuList[i]);
}
}
private function checkForChildren(node:XML):void
{
trace(node.children.length()); //outputs 0's
}
EDIT: found some problems in the code so I edited them but I'm still stuck...