# Urgent help! horizontal xml menu width needs to be text width

**URL:** https://forum.kirupa.com/t/urgent-help-horizontal-xml-menu-width-needs-to-be-text-width/170088
**Category:** Uncategorized
**Created:** [November 22, 2005, 6:18pm UTC](https://forum.kirupa.com/t/urgent-help-horizontal-xml-menu-width-needs-to-be-text-width/170088 "2005-11-22T18:18:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![thesainter](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@thesainter](https://forum.kirupa.com/u/thesainter)
#### Post date: [November 22, 2005, 6:18pm UTC](https://forum.kirupa.com/t/urgent-help-horizontal-xml-menu-width-needs-to-be-text-width/170088/1 "2005-11-22T18:18:41Z")

</div>

Please could someone help me with the following. I have been through this tutorial [http://www.kirupa.com/developer/act…opdown\_menu.htm](http://../developer/actionscript/xml_dropdown_menu.htm) of the xml drop down menu. Made some adjustments with help from other posts to make it horizontal.

but the width of the buttons (menu items) need to be created/adjusted according to the text. and not according the movie it created.

Could someone help me solve this problem? I just can’t get it done.

the as:  
// generates a list of menu items (effectively one menu)  
// given the inputted parameters. This makes the main menu  
// as well as any of the submenus  
GenerateMenu = function(container, name, x, y, depth, node\_xml, direction) {  
// variable declarations  
var curr\_node;  
var curr\_item;  
var curr\_menu = container.createEmptyMovieClip(name, depth);

```
 // for all items or XML nodes (items and menus)
 // within this node_xml passed for this menu
 for (var i=0; i&lt;node_xml.childNodes.length; i++) {
     // movieclip for each menu item
     curr_item = curr_menu.attachMovie("menuitem","item"+i+"_mc", i);
     curr_item._width = childNodes.length;
     
     
     if (direction == "horizontal") {
     curr_item._x = x + i*curr_item._width;
     curr_item._y = y;
     }
     if (direction == "vertical") {
     curr_item._x = x;
     curr_item._y = y + i*curr_item._height;
     }

     curr_item.trackAsMenu = true;
     
     // item properties assigned from XML
     curr_node = node_xml.childNodes*;
     curr_item.action = curr_node.attributes.action;
     curr_item.variables = curr_node.attributes.variables;
     curr_item.name.text = curr_node.attributes.name;
     
     // item submenu behavior for rollover event
     if (node_xml.childNodes*.nodeName == "menu"){
         // open a submenu
         curr_item.node_xml = curr_node;
         curr_item.onRollOver = curr_item.onDragOver = function(){
             var x = this._x + this._width - 186.3;
             var y = this._y + 26;
             GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml, "vertical");
             // show a hover color
             this.name.textColor = (0xFFFFFF);
             var col = new Color(this.background);
             col.setRGB(0x008185);
         };
     }else{ // nodeName == "item"
         curr_item.arrow._visible = false;
         // close existing submenu
         curr_item.onRollOver = curr_item.onDragOver = function(){
             curr_menu.submenu_mc.removeMovieClip();
             // show a hover color
             this.name.textColor = (0xCCCCCC);
             var col = new Color(this.background);
             col.setRGB(0x008185);
         };
     }
     
     curr_item.onRollOut = curr_item.onDragOut = function(){
         // restore color
         this.name.textColor = (0x004445);
         var col = new Color(this.background);
         col.setTransform({ra:100,rb:0,ga:100,gb:0,ba:100,b b:0});
     };
     
     // any item, menu opening or not can have actions
     curr_item.onRelease = function(){
         Actions[this.action](this.variables);
         CloseSubmenus();
     };
 } // end for loop

```

};

// create the main menu, this will be constantly visible  
CreateMainMenu = function(x, y, depth, menu\_xml){  
// generate a menu list  
GenerateMenu(this, “mainmenu\_mc”, x, y, depth, menu\_xml.firstChild, “horizontal”);  
// close only submenus if visible durring a mouseup  
// this main menu (mainmenu\_mc) will remain  
mainMenu\_mc.onMouseUp = function(){  
if (mainmenu\_mc.submenu\_mc && !mainmenu\_mc.hitTest(\_root.\_xmouse, \_root.\_ymouse, true)){  
CloseSubmenus();  
}  
};  
};

// closes all submenus by removing the submenu\_mc  
// in the main menu (if it exists)  
CloseSubmenus = function(){  
mainmenu\_mc.submenu\_mc.removeMovieClip();  
};

// This actions object handles methods for actions  
// defined by the XML called when a menu item is pressed

Actions = Object();  
Actions.loadSWF = function(targetMovie) {  
if (section != targetMovie) {  
section = targetMovie;  
\_root.transition.gotoAndPlay(“closing”);  
};  
}

Actions.newMenu = function(menuxml){  
menu\_xml.load(menuxml);  
};

// load XML, when done, run CreateMainMenu to interpret it  
menu\_xml = new XML();  
menu\_xml.ignoreWhite = true;  
menu\_xml.onLoad = function(ok){  
// create main menu after successful loading of XML  
if (ok){  
CreateMainMenu(1, 110, 0, this);  
}else{  
message\_txt.text = “Error Loading XML”;  
}  
};  
// load first XML menu  
menu\_xml.load(“menu2.xml”);

// preload function and transition  
this.createEmptyMovieClip(“temp”, 1000);  
function preload() {  
this.transition.txtPercentage = “”;  
temp.onEnterFrame = function() {  
var t = this.\_parent.content.getBytesTotal(), l = this.\_parent.content.getBytesLoaded();  
if (t) {  
var percent = Math.round(l\*100/t);  
if (l == t) {  
this.\_parent.transition.gotoAndPlay(“opening”);  
this.\_parent.transition.txtPercentage = “Done Loading”;  
delete this.onEnterFrame;  
} else {  
this.\_parent.transition.txtPercentage = percent+" %";  
}  
} else {  
this.\_parent.transition.txtPercentage = “”;  
}  
};  
}

the xml:

\<?xml version=“1.0”?\>  
\<menu name=“example”\>  
\<item name=“MISSIE” action=“loadSWF” variables=“home.swf”/\>

```
 &lt;item name="OVER het bedrijf" action="loadSWF" variables="shutter2.swf"/&gt;
 &lt;item name="EXPERTISE" action="loadSWF" variables="shutter2.swf"/&gt;
 &lt;item name="BENADERING" action="loadSWF" variables="shutter2.swf"/&gt;
     &lt;menu name="WERK DAT WERKT"&gt;
     &lt;item name="Graphic Design" action="loadSWF" variables="graphics.swf"/&gt;
     &lt;item name="Flash Design" action="loadSWF" variables="flash.swf"/&gt;
     &lt;item name="CSS/HTML/JS" action="loadSWF" variables="css.swf"/&gt;
 &lt;/menu&gt;
 &lt;item name="MENSEN" action="loadSWF" variables="shutter2.swf"/&gt;
 &lt;item name="WERKEN BIJ het bedrijf" action="loadSWF" variables="shutter2.swf"/&gt;
 &lt;item name="CONTACT" action="loadSWF" variables="shutter2.swf"/&gt;    
 

 
 
     &lt;menu name="MISSIE"&gt;
     &lt;item name="Graphic Design" action="loadSWF" variables="graphics.swf"/&gt;
     &lt;item name="Flash Design" action="loadSWF" variables="flash.swf"/&gt;
     &lt;item name="CSS/HTML/JS" action="loadSWF" variables="css.swf"/&gt;
 &lt;/menu&gt;
 
 &lt;item name="Careers" action="loadSWF" variables="careers.swf"/&gt;
 
 &lt;menu name="Downloads"&gt;
     &lt;item name="Application" action="loadSWF" variables="appform.swf"/&gt;
     &lt;item name="Other Forms" action="loadSWF" variables="other.swf"/&gt;
 &lt;/menu&gt;
 
 
 &lt;item name="Contact" action="loadSWF" variables="contact.swf"/&gt;

```

\</menu\>

I have added the fla so you can use it to view or edit.  
Its here same post :[http://www.kirupa.com/forum/showthread.php?t=200043](http://www.kirupa.com/forum/showthread.php?t=200043)
