Hi Sid for some reason that still doesn't work, it's not spacing the buttons
out, it also seems to be treating all the buttons as just one button, and
when i trace out the value of runningX it only gives me one value,
any ideas, many thanks again, Thomas
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.width + 10;// +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);
}
}
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Sidney de
Koning
Sent: 26 August 2009 10:42
To: Flash Coders List
Subject: Re: [Flashcoders] spacing horizontal dynamic xml menu textfields
Hi Thomas,
In the nav item objects you are creating you can override the width
and height functions, like so;
override public function get width( ):Number {
// The plus 4 makes it look better, change this if you like
return _myTextfield.textWidth + 4;
}
Then it will all have a different width.
Oh i just see that you have to use width since navItem is not a
textfield, but uses a textfield so it does not have the textWidth
funtion. Try that :)
runningX += navItem.width + 20;
Oh and just a (real important) note, it is very good practice to
always create classes with a capital letter, so it then becomes
NavItem instead of navItem.
Cheers,
Sid
On Aug 26, 2009, at 10:28 AM, thomas horner wrote:
> Hi Sid many thanks for the demo, have managed to incorporate this
> successfully into what I was doing, and evenly space the items, but
> am
> struggling to space the items,
>
> as per line;
>
> runningX += textheader.textwidth + 20; //20 is the offset or padding
> between the items, however for some reason there is no gap and all
> the items
> are butted up to one another?
>
> many thanks, in advance , Thomas
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Sidney de
> Koning - Funky Monkey Studios
> Sent: 25 August 2009 16:44
> To: Flash Coders List
> Subject: RE: [Flashcoders] spacing horizontal dynamic xml menu
> textfields
>
> He Thomas,
>
> This stuff can be a bit difficult when making the transition.
> Textfield has a really cool property called textWidth and
> textHeight, that
> retruns only the width and height of the actual height :)
>
> I have put comment in the code that explain it. Here is an example
> to demo:
>
> var runningX:Number = 0;
>
> // This is basically your data comming from XML
> var itemsArr:Array = new Array("one", "different length", "piece of
> text",
> "last bit", "evently spaced");
>
> // It does not really matter what kind of loop you do, it is the way
> of
> spacing them thst matters, so you can do your loop like you normally
> would,
> // here i'm just using an array to demonstrate
> for (var index:int = 0; index < itemsArr.length ; index++) {
>
> // You create items of any kind you like...
> var _textheader:TextField = new TextField( );
> _textheader.text = itemsArr[index];
> _textheader.autoSize = TextFieldAutoSize.LEFT;
>
> // 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)
> _textheader.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 += _textheader.textWidth + 20; // +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.
> addChild(_textheader);
> }
>
> Any questions, just ask :)
>
> Cheers, Sid
>> im using it with in the gaia framework do you know it? below is my
>> loop
>> and
>> 'navbut.x' is what im trying to find, i need to add all the widths
>> of all
>> the dynamic textfields sequentially and then space them out evenly
>> horizontally ,
>>
>> im just totally stuck!
>>
>>
>> for each (var section:XML in siteNav.section) {
>>
>> navbut = new navItem();
>>
>>
>> navbut.label.autoSize=TextFieldAutoSize.LEFT;
>>
>>
>> //Insert the menu text (li...@name reads the
>> link's "name" attribute)
>> navbut.label.text=secti...@name;
>> //Assign an url to a menu item
>> navbut.linkto=secti...@src;
>> navbut.keepopen=secti...@keep;
>> navbut.isclicked=secti...@highlight;
>>
>> //Insert the menu button to stage
>>
>> navbut.y=0;
>>
>> trace(total);
>>
>> navbut.x= ?;
>>
>> nav1.addChild(navbut);
>>
>>
>> //Make the button look like a button (hand
>> cursor)
>> navbut.buttonMode=true;
>> navbut.mouseChildren=false;
>> navbut.alpha=0;
>> navbut.name=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);
>>
>>
>> //trace(navbut.x);
>>
>> //Increment the menu button counter, so we
>> know how many buttons there are
>> i++;
>> }
>> }
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of
>> Sidney de
>> Koning - Funky Monkey Studios
>> Sent: 25 August 2009 15:52
>> To: Flash Coders List
>> Subject: RE: [Flashcoders] spacing horizontal dynamic xml menu
>> textfields
>>
>> No problem :)
>> This is using AS3. Where do you have problem with?
>>
>> Sid
>>
>>
>>> is this using as2 as im trying to do it in as3 so am a bit confused
>>>
>>> -----Original Message-----
>>> From: [email protected]
>>> [mailto:[email protected]] On Behalf Of
>>> Sidney
>>> de
>>> Koning
>>> Sent: 25 August 2009 15:22
>>> To: Flash Coders List
>>> Subject: Re: [Flashcoders] spacing horizontal dynamic xml menu
>>> textfields
>>>
>>> Yup that is correct. X and width, Y and height.
>>>
>>> Good luck!
>>>
>>> Sid
>>>
>>> On Aug 25, 2009, at 3:36 PM, thomas horner wrote:
>>>
>>>> Hi thanks, so this is for a vertical menu or positioning vertical
>>>> textFields,
>>>>
>>>> i will try and adjust this for horizontal purposes and measure the
>>>> width as
>>>> opposed to the height then?
>>>>
>>>> -----Original Message-----
>>>> From: [email protected]
>>>> [mailto:[email protected]] On Behalf Of
>>>> Sidney de
>>>> Koning
>>>> Sent: 25 August 2009 14:22
>>>> To: Flash Coders List
>>>> Subject: Re: [Flashcoders] spacing horizontal dynamic xml menu
>>>> textfields
>>>>
>>>> Hi Thomas,
>>>>
>>>> Try to do something like this and adjust it to your own needs;
>>>>
>>>> // When you are in a for loop, create new items and and try to
>>>> measure
>>>> the height of an item.
>>>> // And position items vertically.You need to remember the previous
>>>> item, the fastest way to do this is to have a runningY var declared
>>>> outside the for loop with an initial value of zero.
>>>> //See comments in code for further explanation.
>>>>
>>>> var runningY:Number = 0;
>>>> var OFFSET_X:Number = 20;
>>>>
>>>> for (var index:int = 0; index < 4 ; index++) {
>>>>
>>>> var _textheader:TextField = new TextField( );
>>>> _textheader.text = "Text";
>>>> _textheader.autoSize = TextFieldAutoSize.LEFT;
>>>> _textheader.x = _background.x - _background.width / 2 + OFFSET_X;
>>>> // First iteration runningY = 0;
>>>> // Second iteration runningY = 0 + textHeader.height +2;
>>>> textHeader.height = 20
>>>> // Third iteration runningY = 22 + textHeader.height +2;
>>>> textHeader.height = 40 -- mutiple lines of text
>>>> // Fourth iteration runningY = 64 + textHeader.height +2;
>>>> textHeader.height = 20
>>>> // Fifth iteration runningY = 86
>>>> _textheader.y = runningY;
>>>> runningY += _textheader.height + 2; // textheader = 20
>>>> }
>>>>
>>>>
>>>>
>>>> On Aug 25, 2009, at 3:06 PM, thomas horner wrote:
>>>>
>>>>>
>>>>>
>>>>> Hi all am struggling to position, my textFields generated within
>>>>> my
>>>>> loop
>>>>> from my external xml,
>>>>>
>>>>>
>>>>>
>>>>> i want to evenly space them and as they are dynamic they are all
>>>>> of
>>>>> different sizes.
>>>>>
>>>>>
>>>>>
>>>>> i have run a trace on the loop as follows;
>>>>>
>>>>>
>>>>>
>>>>> trace(navbut.label.width);
>>>>>
>>>>>
>>>>>
>>>>> which gives me the widths of each field how do it add the total of
>>>>> the
>>>>> widths from the loop? to then space them.
>>>>>
>>>>> _______________________________________________
>>>>> Flashcoders mailing list
>>>>> [email protected]
>>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>
>>>> _______________________________________________
>>>> Flashcoders mailing list
>>>> [email protected]
>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>
>>>> _______________________________________________
>>>> Flashcoders mailing list
>>>> [email protected]
>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>> _______________________________________________
>>> Flashcoders mailing list
>>> [email protected]
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>> _______________________________________________
>>> Flashcoders mailing list
>>> [email protected]
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>
>>
>> --
>> Hire me to do your website, businesscards, presentations or flyers.
>> --
>> Only those who dare to fail greatly can ever achieve greatly. -
>> Robert F.
>> Kennedy
>> --
>> Sidney de Koning | Flash Developer/Creative Soul/Multimedialist
>> Funky Monkey Studios | Van Ostadestraat 286 HS | 1073 TW |
>> Amsterdam |
>> e:[email protected] | tel: +31(06)24 548336 | fax: +31 (0)84
>> 747 7288
>>
>>
>>
>> _______________________________________________
>> Flashcoders mailing list
>> [email protected]
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>> _______________________________________________
>> Flashcoders mailing list
>> [email protected]
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>
>
> --
> Hire me to do your website, businesscards, presentations or flyers.
> --
> Only those who dare to fail greatly can ever achieve greatly. -
> Robert F.
> Kennedy
> --
> Sidney de Koning | Flash Developer/Creative Soul/Multimedialist
> Funky Monkey Studios | Van Ostadestraat 286 HS | 1073 TW | Amsterdam |
> e:[email protected] | tel: +31(06)24 548336 | fax: +31 (0)84
> 747 7288
>
>
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders