tags:

views:

109

answers:

2

hi,

I cannot center the components in my VBox. I would like to set the standard css element "align: center". How can I do that in Flex ?

<mx:VBox>
    <mx:LinkButton label="Tag1" />
    <mx:Image source="@Embed(source='../icons/userIcon.png')" />
    <mx:Label id="username" text="Nickname" visible="false" fontWeight="bold"   />
</mx:VBox>

thanks

+1  A: 

Simply put, you can do this:

<mx:VBox width="200" horizontalAlign="center">
    <mx:Label text="foo" />
</mx:VBox>

I just tried this example, and it worked fine. If the container's width is being dictated by its children, it might not appear to align correctly:

<mx:VBox horizontalAlign="center" borderStyle="solid">
    <mx:Label text="foo" />
    <mx:Label text="bar" />
</mx:VBox>

However, further specifying the width shows this attribute to work:

<mx:VBox width="200" horizontalAlign="center" borderStyle="solid">
    <mx:Label text="foo" />
    <mx:Label text="bar" />
</mx:VBox>
bedwyr
i tried, it doesn't work. The elements are aligned on left.
Patrick
I wonder if the VBox width is being set by its children. Try this: make the VBox width about 2x what you expect, and see if the 'horizontalAlign' works.
bedwyr
Sorry, it worked. My fault. The image is still not really centered. Is there any way to set an horizontal offset on it ? thanks
Patrick
A: 

how to use addchild in flex4?