# Calculate horizontal space

**URL:** <https://forum.kirupa.com/t/calculate-horizontal-space/218771>\
**Category:** flash\
**Created:** [March 10, 2007, 9:23pm UTC](https://forum.kirupa.com/t/calculate-horizontal-space/218771 "2007-03-10T21:23:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![W84me](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/w84me/32/1257_2.png) [@W84me](https://forum.kirupa.com/u/W84me)\
**Post date:** [March 10, 2007, 9:23pm UTC](https://forum.kirupa.com/t/calculate-horizontal-space/218771/1 "2007-03-10T21:23:14Z")

</div>

Hi all! I need your help 🙂

I am trying to make a horizontal xml menu. I load the xml and i get the values and i make the buttons. All ok so far. I attach a movieclip to make the buttons. Inside the movieclip is a dynamic textField where i load the text from the xml.

Now i wonder how can i calculate the space between the buttons so the are spaced evenly cause their width is not fixed.

Here is the code

```auto
var navLoad:XML = new XML();
navLoad.load("navigation.xml");
navLoad.ignoreWhite = true;
navLoad.onLoad = function(success:Boolean):Void {
    if (success) {
        //trace("loaded");
        var xmlNode = this.firstChild;
        var total = xmlNode.childNodes.length;
        var butName:Array = [];
        var butTitle:Array = [];
        var butLink:Array = [];
        var spacing = 100;
        for (var i:Number = 0; i<total; i++) {
            butName* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
            butTitle* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
            butLink* = xmlNode.childNodes*.childNodes[2].firstChild.nodeValue;
            var button = attachMovie("button", "button"+i, _root.getNextHighestDepth());
            _root["button"+i].butText.text = butName*;
            _root["button"+i].butText.autoSize = "left";
            _root["button"+i]._x = _root["button"+i]._width*i;
            _root["button"+i]._y = 30;
            _root["button"+i].onRelease = function() {
                trace("pressed");
            };
            
        }
    } else {
        trace("error");
    }
};

```
