# Spacing depending on text width of dynamically generated buttons help!

**URL:** <https://forum.kirupa.com/t/spacing-depending-on-text-width-of-dynamically-generated-buttons-help/309291>\
**Category:** flash\
**Created:** [May 11, 2010, 4:54pm UTC](https://forum.kirupa.com/t/spacing-depending-on-text-width-of-dynamically-generated-buttons-help/309291 "2010-05-11T16:54:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alejandroy](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@alejandroy](https://forum.kirupa.com/u/alejandroy)\
**Post date:** [May 11, 2010, 4:54pm UTC](https://forum.kirupa.com/t/spacing-depending-on-text-width-of-dynamically-generated-buttons-help/309291/1 "2010-05-11T16:54:14Z")

</div>

I have the following AS2 code which creates dynamic buttons based on an array:

```auto

var labels_array:Array = new Array({label_txt:">> arquitectura industrial", gotoX:"partners"}, {label_txt:">> edificación", gotoX:"team"});
var initX:Number = 0;
//row starting X coord
var nextX:Number = initX;
//first X coord for button
var nextY:Number = 0;
//first Y coord for button
var wrapY:Number = 0;
//will start new row after this many buttons
var selectedButton:MovieClip;
var container_mc:String = "";
for (var i:Number = 1; i<labels_array.length; i++) {
    container_mc = "cont"+i;
    this.createEmptyMovieClip(container_mc,this.getNextHighestDepth());
    this[container_mc].attachMovie("button_mc","button_mc",this.getNextHighestDepth,{_x:nextX, _y:nextY});
    this[container_mc].button_mc.stop();
    this[container_mc].button_mc.name_txt.text = labels_array*.label_txt;
    this[container_mc].button_mc.tweenTo = labels_array*.gotoX;
   
    if (i == (wrapY-1)) {
        wrapY += 1;
        //if there were more than two rows this would start new row after every 6 buttons
        //line next button up under first button
        nextX = initX;
        nextY += 0;
    } else {
        //set next button to the right of previous button
        nextX += 140;
    }
}

```

the variable nextX places a new button every given number of pixels, in this case 140px. What I’ll like to do is to make this value dynamic so that a new button is placed taking into account the width of the preceding button, plus a certain number of pixels. I’ve tried my best to do it myself, but I’m not that good with math, can anyone help?

Thanks,
