Button naming and positioning

Hi,

I am trying to assign meaningful names to buttons in a for loop based of the var mainBtn.mName. This would normally be easy but i need to to get the width of the buttons before it (the bold code) to work out the position of each button, any ideas how i can do this?


for (i=0; i<folder.length; i++) {
            var mainBtn:MovieClip = mainMenu.attachMovie("button", "button"+i, i);
            mainBtn.mName = folder*.attributes.name;
            **mainBtn._x += mainMenu["button"+(i-1)]._x+mainMenu["button"+(i-1)]._width+btnSpacing**;