I think this could be simple!!
XML feed to my horizontal menu, i can measure the text width ok, but i can't figure out the algebra on how to layout my menu text side by side with a 20 pixel gap.
PHP Code:
function createMyMenu():void {
//This will be used to represent a menu item
var menuItem:MenuItem;
//Counter
var i:uint = 0;
var w:Number;
var s:Number;
//Loop through the links found in the XML file
for each (var link:XML in xml.link) {
menuItem = new MenuItem();
menuItem.id = i;
//If the text is longer than the textfield, autosize so that the text is
//treated as left-justified text
menuItem.menuLabel.autoSize = TextFieldAutoSize.LEFT;
//Insert the menu text (link.@pgTitle reads the link's "pgTitle" attribute)
menuItem.menuLabel.text = link.@pgTitle;
menuItem.y = 0;
w = menuItem.menuLabel.width;
s = 20;
//// this is wrong /////
menuItem.x = i* (w + s);
//// i cant work it out /////
trace("width"+ w);
//Make the button look like a button (hand cursor)
menuItem.buttonMode = true;
menuItem.mouseChildren = false;
//Add event handlers (used for animating the buttons)
menuItem.addEventListener (MouseEvent.MOUSE_OVER, mouseOverHandler);
menuItem.addEventListener (MouseEvent.MOUSE_OUT, mouseOutHandler);
menuItem.addEventListener (MouseEvent.MOUSE_DOWN, mousePressHandler);
menuMC.addChild(menuItem);
//Increment the menu button counter, so we know how many buttons there are
i++;
}
}