The following example shows how you can set a custom divider color on a Flex DividedBox container (HDividedBox or VDividedBox) by setting the dividerColor style.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/17/setting-a-custom-divider-color-on-the-dividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_dividerColor_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:ApplicationControlBar dock="true">
<mx:Form styleName="plain">
<mx:FormItem label="dividerColor:">
<mx:ColorPicker id="colorPicker" />
</mx:FormItem>
</mx:Form>
</mx:ApplicationControlBar>
<mx:HDividedBox id="dividedBox"
dividerColor="{colorPicker.selectedColor}"
width="100%"
height="100%">
<mx:Box id="box1"
backgroundColor="haloGreen"
width="100%"
height="100%"
minWidth="100" />
<mx:Box id="box2"
backgroundColor="haloBlue"
width="100%"
height="100%"
minWidth="100" />
</mx:HDividedBox>
</mx:Application>
View source is enabled in the following example.
You can also set the dividerColor style in an external .CSS file or <mx:Style /> block, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/17/setting-a-custom-divider-color-on-the-dividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_dividerColor_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Style>
HDividedBox {
dividerColor: red;
}
</mx:Style>
<mx:HDividedBox id="dividedBox"
width="100%"
height="100%">
<mx:Box id="box1"
backgroundColor="haloGreen"
width="100%"
height="100%"
minWidth="100" />
<mx:Box id="box2"
backgroundColor="haloBlue"
width="100%"
height="100%"
minWidth="100" />
</mx:HDividedBox>
</mx:Application>
Or, you can set the dividerColor style using ActionScript, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/17/setting-a-custom-divider-color-on-the-dividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_dividerColor_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.ColorPickerEvent;
private function colorPicker_change(evt:ColorPickerEvent):void {
dividedBox.setStyle("dividerColor", evt.color);
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Form styleName="plain">
<mx:FormItem label="dividerColor:">
<mx:ColorPicker id="colorPicker"
change="colorPicker_change(event);" />
</mx:FormItem>
</mx:Form>
</mx:ApplicationControlBar>
<mx:HDividedBox id="dividedBox"
width="100%"
height="100%">
<mx:Box id="box1"
backgroundColor="haloGreen"
width="100%"
height="100%"
minWidth="100" />
<mx:Box id="box2"
backgroundColor="haloBlue"
width="100%"
height="100%"
minWidth="100" />
</mx:HDividedBox>
</mx:Application>
Due to popular demand, here is the “same” example in a more ActionScript friendly format:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/17/setting-a-custom-divider-color-on-the-dividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_dividerColor_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
initialize="init();">
<mx:Script>
<![CDATA[
import mx.containers.ApplicationControlBar;
import mx.containers.Box;
import mx.containers.Form;
import mx.containers.FormItem;
import mx.containers.HDividedBox;
import mx.controls.ColorPicker;
import mx.events.ColorPickerEvent;
private var colorPicker:ColorPicker;
private var box1:Box;
private var box2:Box;
private var dividedBox:HDividedBox;
private function init():void {
colorPicker = new ColorPicker();
colorPicker.addEventListener(ColorPickerEvent.CHANGE,
colorPicker_change);
var formItem:FormItem = new FormItem();
formItem.label = "dividerColor:";
formItem.addChild(colorPicker);
var form:Form = new Form();
form.styleName = "plain";
form.addChild(formItem);
var appControlBar:ApplicationControlBar;
appControlBar = new ApplicationControlBar();
appControlBar.dock = true;
appControlBar.addChild(form);
addChildAt(appControlBar, 0);
box1 = new Box();
box1.percentWidth = 100;
box1.percentHeight = 100;
box1.minWidth = 100;
box1.setStyle("backgroundColor", "haloGreen");
box2 = new Box();
box2.percentWidth = 100;
box2.percentHeight = 100;
box2.minWidth = 100;
box2.setStyle("backgroundColor", "haloBlue");
dividedBox = new HDividedBox();
dividedBox.percentWidth = 100;
dividedBox.percentHeight = 100;
dividedBox.addChild(box1);
dividedBox.addChild(box2);
addChild(dividedBox);
}
private function colorPicker_change(evt:ColorPickerEvent):void {
dividedBox.setStyle("dividerColor", evt.color);
}
]]>
</mx:Script>
</mx:Application>



Is there a nice way to auto-hide the divided box? or allow the user to click on the divider box button and have it collapse?