Dynamic scaling mxl menu. need help

I have been working on making a menu that gets it’s content from an XML file.

menu.xml


<?xml version="1.0" encoding="iso-8859-1"?>
<links>
    <link name="HOME" ref="index.cfm"/>
    <link name="HOW IT WORKS" ref="hiw.html"/>
    <link name="BUY" ref="photoTut.html"/>
    <link name="PRODUCTS" ref="pducts.html"/>
    <link name="FREE TRIAL" ref="free.html"/>
    <link name="SUPPORT" ref="support.html"/>
</links>

I want to load the menu horirontally and have the buttons resize to the width of the text with a margin on each side. I need the margins to equal the remaining width of the menu stage divided by the menu items(nodes) divided by 2.

I have spent hours on this and now have very choppy actionscript code in my source. Can someone help?

I am willing to take new code. But I don’t want to buy a component.

menu.fla


var linksXML = new XML();
linksXML.ignoreWhite = true;
linksXML.load("menu.xml");
linksXML.onLoad = checkLoading;

var menuWidth:Number = Stage.width;
var depthCount = 0;
var rootNode = linksXML.firstChild;
var tLink = rootNode.firstChild;

function checkLoading(success) {
    if (success == true) {
        var rootNode = linksXML.firstChild;
        var numTabs = rootNode.childNodes.length;
        var newArray = new Array();
        
        //Load the links Text
        var tLink = rootNode.firstChild;
        for (i=0; i<numTabs; i++) {
            createLink("tLink" + i, tLink);
            var totalInner = tLink.childNodes.length;
            var tnLink = tLink.firstChild;
            var total_width = 0;
            for (j=0;j<totalInner; j++){
                myArray[j] = createLink("tnLink" + j + ""+ i, tnLink);
                total_width = total_width + myArray[j].width;

                tnLink = tnLink.nextSibling;
            }
            tLink = tLink.nextSibling;
        }
        
        var marginWidth = (Stage.width - total_width) / numTabs / 2;
        //trace(marginWidth);
        //trace(menuWidth);
        for (j=0; j<myArray.length; j++) {
    
        }
        
        gotoAndStop(2);
    }
}

function setName(obj, theName, Size){
    //_root.baseLink.baseLinkText.autoSize = "center";
    //_root.baseLink.baseLinkText.autoSize = true;
    obj._height = obj._height*Size;
    obj._width = obj._width*Size;
    obj.baseLinkText.text = theName;
    obj.embedFonts = true;
}

function createLink(newObj, aNode){
    var theMovie = duplicateMovieClip(_root.baseLink, newObj, depthCount++);
    var tcl = eval(newObj);
    tcl.aLink = aNode.attributes.ref;
    xPos += Stage.width / numTabs;
    if (aNode.nodeName == "link"){
        setName(tcl, aNode.attributes.name, 1);
        tcl._x = Stage.width / numTabs;
    }
    else{
        setName(tcl, aNode.attributes.name, 0.95);
        tcl._x = Stage.width / numTabs;
    }
    tcl._x = xPos;
    return theMovie;
}

gotoAndStop(1);


The code


this.baseLinkText.autoSize = true;
this.baseLinkBG._width = this.baseLinkText.textWidth + 32;
trace(this.baseLinkText.textWidth);

Is inside the base movie clips

Any help would be swell.