thanks steven, again! i had already managed to get the sids version going
inside my build, but was just getting problems with adding spacing between
them.
for some reason now though all my buttons are acting as one when i
mouseOver,
siteNav=IXml(assets.siteNav).xml;
var runningX:Number=0;
var padding:Number=50;
var itemsArr:Array=new Array(sitenav.secti...@name);
for (var index:int = 0; index < itemsArr.length;
index++) {
// You create items of any kind you like...
var navbut:navItem = new navItem( );
//assign the menu text from the navxml
navbut.label.text=itemsArr[index];
navbut.label.autoSize=TextFieldAutoSize.LEFT;
//Assign an url to a menu item
navbut.linkto=sitenav.secti...@src;
//read instructions fomr nav xml
navbut.keepopen=sitenav.secti...@keep;
navbut.isclicked=sitenav.secti...@highlight;
//Make the button look like a button (hand
cursor)
navbut.buttonMode=true;
navbut.mouseChildren=false;
navbut.alpha=0;
navbut.name=sitenav.secti...@url;
TweenMax.to(navbut, 0.5, {alpha:1});
//Add event handlers (used for animating the
buttons)
navbut.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
navbut.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
navbut.addEventListener(MouseEvent.CLICK,
mouseClickHandler);
// You say that runningX is some value.
since it was zero in the beginning we are adding the value ontop of its
current value (see line below)
navbut.x=runningX;
// ... And then you space them. You can use
textWidth if using text width or plain width for object that extend from
DisplayObjects or Sprites etc...
runningX+=navbut.textWidth+padding;// +10 is
the offset between the items you want ot use. Can be any number.
// And then you add the child to the display
list so it becomes visible.
nav1.addChild(navbut);
trace(runningX);
}
}
function mouseClickHandler(e:Event):void {
}
function mouseOverHandler(e:Event):void {
TweenMax.to(e.target, 0.25, {tint:0x888888})
}
function mouseOutHandler (e:Event):void {
if (e.target.alpha < 1) {
TweenMax.to(e.target, 0.25, { alpha:0.3 } )
} else {
//do nothing
}
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Steven Sacks
Sent: 26 August 2009 09:53
To: Flash Coders List
Subject: Re: [Flashcoders] spacing horizontal dynamic xml menu textfields
As I described on my forum post, you have to first put your items in an
array.
var items:Array = [all, of, your, items];
var len:int= items.length;
var i:int;
Then, you do the following measurements:
// the right of the last item minus the left of the first item
var availableWidth:Number = items[len - 1].x + items[len -1].width -
items[0].x;
// the total widths of all the items
var totalWidth:Number = 0;
i = len;
while (i--)
{
totalWidth += items[i].textWidth;
}
//Subtract the totalWidth from availableWidth to get the remainingWidth
var remainingWidth:Number = availableWidth - totalWidth;
// Divide remainingWidthby the number of items
var gapWidth:Number = remainingWidth / len;
// iterate through your array setting the x positions
// of the items based on the previous item's width and the gap.
var lastX:Number = 0;
for (i= 0; i < len; ++i)
{
items[i].x = lastX;
lastX = items[i].textWidth + gapWidth;
}
// That's all there is to it.
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders