# Xml drop down menu

**URL:** <https://forum.kirupa.com/t/xml-drop-down-menu/280443>\
**Category:** Uncategorized\
**Created:** [January 27, 2009, 6:56pm UTC](https://forum.kirupa.com/t/xml-drop-down-menu/280443 "2009-01-27T18:56:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wraj](https://avatars.discourse-cdn.com/v4/letter/w/41988e/32.png) [@wraj](https://forum.kirupa.com/u/wraj)\
**Post date:** [January 27, 2009, 6:56pm UTC](https://forum.kirupa.com/t/xml-drop-down-menu/280443/1 "2009-01-27T18:56:47Z")

</div>

I’m trying to create a drop down menu similar to this  
[http://www.kirupa.com/developer/actionscript/xml\_dropdown\_menu.htm](http://www.kirupa.com/developer/actionscript/xml_dropdown_menu.htm)

but instead of a vertical menu, i want to create a menu that is horizontal.

when i try this, I cant get the submenu to be in the center. please see the attached image.

any ideas?

thanks  
Wraj.

==============SOURCE START=====================

menu\_xml = new XML();  
menu\_xml.ignoreWhite = true;  
menu\_xml.onLoad = function(ok)  
{  
if(ok)  
{  
trace(“XML file loaded”);  
Createmainmenu(0,0,0,this);  
}  
};

menu\_xml.load(“menu.xml”);

//function that create the menu using the generate menu function  
Createmainmenu = function(x,y,depth,menu\_xml)  
{  
GenerateMenu(this,“mainmenu\_mc”,x,y,depth,menu\_xml.firstChild); //generate a menu  
mainmenu\_mc.onMouseUp = function()  
{  
if(mainmenu\_mc.submenu\_mc && !mainmenu\_mc.hitTest(\_root.xouse, \_rot.ymouse, true))  
{  
CloseSubmenus();  
}  
};  
};

//remove submenus.  
CloseSubmenus = function()  
{  
mainmenu\_mc.submenu\_mc.removeMovieClip();  
};

//function that generates a menu iteratively  
GenerateMenu = function(container, name, x, y, depth, xml\_node)  
{  
trace(“generate Menu called”);  
var curr\_node;  
var curr\_item;  
var curr\_menu = container.createEmptyMovieClip(name,depth);

```
//loop through to attach menuitem clips
for(var i=0; i&lt;xml_node.childNodes.length; i++)
{
    trace("attaching clip "+i);
    curr_item = curr_menu.attachMovie("menuitem","menu_item"+i,depth+i);
    curr_item._y = y;
    curr_item._x = x + i*curr_item._width;
    curr_item.trackAsMenu = true;
    
    curr_menu._x = (Stage.width/2) - (((i+1)*150)/2); //CENTERING SUBMENUS
    
    //insert attributes into the menu item
    curr_node = xml_node.childNodes*;
    curr_item.button_text.text = curr_node.attributes.name;
    
    if(xml_node.childNodes*.nodeName == "menu")
    {
        curr_item.xml_node = curr_node;
        curr_item.onRollOver = curr_item.onDragOver = function()
        {
            var y = this._y + 25;
            GenerateMenu(curr_menu,"submenu_mc",x,y,1000,this.xml_node);
        }
    }
    else
    {
        curr_item.arrow._visible = false;
        curr_item.onRollOver = curr_item.onRollOver = curr_item.onDragOver = function()
        {
            curr_menu.submen_mc.removeMovieClip();
        }
    }
}

```

};

//button actions  
Actions = Object();  
Actions.gotoURL = function(urlVar)  
{  
getURL(urlVar,"\_blank");  
};

Actions.newTab = function()  
{  
//create a new tab for second level menu  
}

=====================SOURCE END ==============
