Advanced XML Drop Menu

Hey guys, I’ve got a tough one (for me atleast :P). I’m trying to get a drop down menu to populate from an XML document. I have categories and sub categories. I have included the XML, and the AS so that you should just be able to copy/past and see what it’s doing. Sorry I forgot to put this in the title, I’m working in Flash 8

Here is the XML:

<?xml version=“1.0”? encoding=“UTF-8”?>
<main name=“web desgins” sub=“true”>
<sub name=“category 1”/>
<sub name=“category 2”/>
<sub name=“category 3”/>
<sub name=“category 4”/>
<sub name=“category 5”/>
<sub name=“category 6”/>
<main name=“flash” sub=“true”>
<sub name=“category 1”/>
<sub name=“category 2”/>
<sub name=“category 3”/>
<sub name=“category 4”/>
<main name=“video” sub=“false”/>
<main name=“audio” sub=“false”/>
<main name=“test new” sub=“false”/>

The flash I’ve got is (sorry it’s quite lengthy):

var spacing:Number = new Number();
var menu_spacing:Number = new Number();

menu_spacing = 25;
spacing = 1.5;

function loadMenu(my_xmlmenu){
var categories = my_xmlmenu.firstChild.firstChild.childNodes;
for(var i = 0; i < categories.length; i++){
var currCat = categories*;
var hasSub = categories*.attributes.sub;

var currCat_mc = menu.createEmptyMovieClip(“cholder”+i, +i, i);
currCat_mc._x = menu._x - 40;
currCat_mc._y = (i*(menu_spacing/spacing)) + 25;

if(hasSub == “true”){
var subCat = my_xmlmenu.firstChild.firstChild.firstChild.childNodes;

for(var j = 0; j < subCat.length; j++){
var currSub = subCat[j];

var currSub_mc = menu.createEmptyMovieClip(“sholder”+j, (+j + categories.length), j);
currSub_mc._x = currCat_mc._x + 15;
currSub_mc._y = 40 + (j/spacing * currCat_mc._y);

currSub_mc.createTextField(“scat”, +j, 0, 0, 0, 0);
currSub_mc.scat.text = currSub;
currSub_mc._visible = false;

var sformat = new TextFormat();

sformat.color = 0xFFFFFF;
sformat.font = “_sans”;
sformat.bold = true;
sformat.size = 12;

currSub_mc.scat.autoSize = true;
currSub_mc.scat.selectable = false;

currCat_mc.createTextField(“mcat”, +i, 0, 0, 0, 0);
currCat_mc.mcat.text = currCat;

var mformat = new TextFormat();

mformat.color = 0xFFFFFF;
mformat.font = “_sans”;
mformat.bold = true;
mformat.size = 12;

currCat_mc.mcat.autoSize = true;
currCat_mc.mcat.selectable = false;

var my_xmlmenu:XML = new XML();
my_xmlmenu.ignoreWhite = true;
my_xmlmenu.onLoad = function(success){

I’ve got it to populate the main menu and the first subMenu ok, but the problem I’m running into is that it’s reading the second subMenu (“flash”) as having 6 categories rather than 4. I’m not sure whats happening in the for(){} that is causing this, but I can’t figure it out. Also it will populate the first, but not the second subMenu (even with the incorrect number of categories), and changes the spacing of the first for some reason.

Also I want to add onRelease() events to the main menu to display/hide the subMenus with tween() effects, and am at kind of a loss as how to do that. I have tried putting the onRelease() in either of the for(){}, or outside of both, but it didn’t quite work so I’m not quite sure where to put it.

Any help would be very much appreciated.

Thank you.