tags:

views:

555

answers:

3

is it possible to make the child elements of a vbox to occupy 100% of the width without indicating width=100% for each element ?

+1  A: 

You could make the elements a custom component and specify width="100%" in the component. Otherwise, no.

You can also bind the width property to the parents width property, which would have much the same affect.

Joel Hooks
A: 

No... you'll have to add a width for each button. The vbox will ask the Button how much space it wants to take up. So you need to tell the button to try and take 100% of the width.

It shouldn't be a problem and is quite common to have width and height attributes on the majority of components, both functional and layout.

James Hay
+1  A: 

A VBox's layout algorithm will look at the children's width to decide how to lay them out. If you want to "automatically" set them to 100%, no matter what they are, then the way to do that is to trap when the child is added and set its percentWidth to 100 in the event handler, or else subclasses and loop over the children in a suitable overridden method e.g. createChildren.

Vinay Sajip
can you show me the code for the eventhandler like onChildAdd(???) and i also don't know how to set width to 100% in actionscript
Omu
in actionscript flex components can be set to percent width like: myComponent.percentWidth = 100;
Joel Hooks