The following example shows how you can align controls in a Flex ControlBar container by setting the horizontalAlign style.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/02/24/aligning-items-horizontally-in-a-controlbar-container-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.ItemClickEvent;
private function toggleButtonBar_itemClick(evt:ItemClickEvent):void {
cBar.setStyle("horizontalAlign", evt.label);
}
]]>
</mx:Script>
<mx:Array id="arr">
<mx:Object label="left" />
<mx:Object label="center" />
<mx:Object label="right" />
</mx:Array>
<mx:ApplicationControlBar dock="true">
<mx:Form styleName="plain">
<mx:FormItem label="horizontalAlign:">
<mx:ToggleButtonBar id="toggleButtonBar"
dataProvider="{arr}"
selectedIndex="0"
itemClick="toggleButtonBar_itemClick(event);" />
</mx:FormItem>
</mx:Form>
</mx:ApplicationControlBar>
<mx:Panel id="panel"
width="320"
height="160">
<mx:Label text="Button" />
<mx:Label text="ButtonBar" />
<mx:Label text="CheckBox" />
<mx:Label text="ColorPicker" />
<mx:Label text="ComboBox" />
<mx:Label text="DataGrid" />
<mx:ControlBar id="cBar">
<mx:Button label="Submit" />
<mx:Button label="Cancel" />
</mx:ControlBar>
</mx:Panel>
</mx:Application>
View source is enabled in the following example.
You can also set the horizontalAlign style in an external .CSS file or within an <mx:Style /> block, as seen in the following snippet:
<mx:Style>
ControlBar {
horizontalAlign: center;
}
</mx:Style>
Or, you can set the horizontalAlign style in MXML directly, using the following snippet:
<mx:ControlBar id="cBar" horizontalAlign="center">
<mx:Button label="Submit" />
<mx:Button label="Cancel" />
</mx:ControlBar>




I’m Korean. Thank you very much!!!