Disabling dividers in an HDividedBox container in Flex
The following example shows how you can disable the dividers in a Flex HDividedBox container by using the numDividers property, getDividerAt() method, and setting the visible property.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/10/11/disabling-dividers-in-an-hdividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_getDividerAt_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
private function checkBox_change(evt:Event):void {
var value:Boolean = !checkBox.selected;
var idx:uint;
var len:uint = hDividedBox.numDividers;
for (idx = 0; idx < len; idx++) {
hDividedBox.getDividerAt(idx).visible = value;
}
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:CheckBox id="checkBox"
label="Disable dividers:"
labelPlacement="left"
change="checkBox_change(event);" />
</mx:ApplicationControlBar>
<mx:HDividedBox id="hDividedBox"
width="100%"
height="100%">
<mx:HBox id="hBox1"
width="100%"
height="100%"
backgroundColor="haloGreen">
</mx:HBox>
<mx:HBox id="hBox2"
width="100%"
height="100%"
backgroundColor="haloBlue">
</mx:HBox>
<mx:HBox id="hBox3"
width="100%"
height="100%"
backgroundColor="haloOrange">
</mx:HBox>
</mx:HDividedBox>
</mx:Application>
View source is enabled in the following example.
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/10/11/disabling-dividers-in-an-hdividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_getDividerAt_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.HBox;
import mx.containers.HDividedBox;
import mx.controls.ButtonLabelPlacement;
import mx.controls.CheckBox;
private var checkBox:CheckBox;
private var hBox1:HBox;
private var hBox2:HBox;
private var hBox3:HBox;
private var hDividedBox:HDividedBox;
private function init():void {
checkBox = new CheckBox();
checkBox.label = "Disable dividers:";
checkBox.labelPlacement = ButtonLabelPlacement.LEFT;
checkBox.addEventListener(Event.CHANGE,
checkBox_change);
var appControlBar:ApplicationControlBar;
appControlBar = new ApplicationControlBar();
appControlBar.dock = true;
appControlBar.addChild(checkBox);
addChildAt(appControlBar, 0);
hBox1 = new HBox();
hBox1.percentWidth = 100;
hBox1.percentHeight = 100;
hBox1.setStyle("backgroundColor", "haloGreen");
hBox2 = new HBox();
hBox2.percentWidth = 100;
hBox2.percentHeight = 100;
hBox2.setStyle("backgroundColor", "haloBlue");
hBox3 = new HBox();
hBox3.percentWidth = 100;
hBox3.percentHeight = 100;
hBox3.setStyle("backgroundColor", "haloOrange");
hDividedBox = new HDividedBox();
hDividedBox.percentWidth = 100;
hDividedBox.percentHeight = 100;
hDividedBox.addChild(hBox1);
hDividedBox.addChild(hBox2);
hDividedBox.addChild(hBox3);
addChild(hDividedBox);
}
private function checkBox_change(evt:Event):void {
var value:Boolean = !checkBox.selected;
var idx:uint;
var len:uint = hDividedBox.numDividers;
for (idx = 0; idx < len; idx++) {
hDividedBox.getDividerAt(idx).visible = value;
}
}
]]>
</mx:Script>
</mx:Application>
If you want to remove the gap between the HDividedBox children after disabling the dividers, you can set the horizontalGap style, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/10/11/disabling-dividers-in-an-hdividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_getDividerAt_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
private function checkBox_change(evt:Event):void {
var hGap:Class = hDividedBox.getStyle("dividerSkin");
var value:Boolean = !checkBox.selected;
var idx:uint;
var len:uint = hDividedBox.numDividers;
for (idx = 0; idx < len; idx++) {
hDividedBox.getDividerAt(idx).visible = value;
}
if (value) {
hDividedBox.setStyle("horizontalGap", hGap.width);
} else {
hDividedBox.setStyle("horizontalGap", 0);
}
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:CheckBox id="checkBox"
label="Disable dividers:"
labelPlacement="left"
change="checkBox_change(event);" />
</mx:ApplicationControlBar>
<mx:HDividedBox id="hDividedBox"
minHeight="100"
width="100%"
height="100%">
<mx:HBox id="hBox1"
minWidth="20"
width="100%"
height="100%"
backgroundColor="haloGreen">
</mx:HBox>
<mx:HBox id="hBox2"
minWidth="20"
width="100%"
height="100%"
backgroundColor="haloBlue">
</mx:HBox>
<mx:HBox id="hBox3"
minWidth="20"
width="100%"
height="100%"
backgroundColor="haloOrange">
</mx:HBox>
</mx:HDividedBox>
</mx:Application>
View source is enabled in the following example.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
11 Responses to Disabling dividers in an HDividedBox container in Flex
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


Hi,
Is it possible to change only one of the dividers settings? I would like to have one with a determined gap size and the other with a different one, but I can only change this parameter in the dividedbox, any help?
Luis Ramos,
Sorry, I don’t believe it is possible to set separate horizontal gap widths in an HDividedBox or HBox container.
You could try filing an enhancement request at http://bugs.adobe.com/flex/
Peter
What if we wanted to make each hbox collapsable when clicked on to lets say 20px. The last hbox can not be collapsed because the HDividedBox wont resize automaticaly. That would be a good demo to show.
Thank you so much Peter, this is exactly what I was looking for. You and your site are always so helpful for my flex needs. Thank you!
This is great but I wish there was an easier way. It would be great if the HDividedBox simply had a boolean toggle to show/hide all the resize bars.
Thanks for this example, i was looking for this problem.
Thank you very much !! but i got one little stupid question :(
in you example you always make a checkbox but i want it to implement without offcourse the checkbox; What do i have to do in the code so it will run with the option of the checkbox
What do we have to change in de script ?? Thank you for the help !!
without the option of the checkbox offcourse excuse me .
Its very nice example which exactly suits my requirement. Thanks
I would actually recommend using styles to hide the HDividedBox divider. You can do so by setting the divider-affordance and the divider-thickness. You can also adjust the gap between the divided children by setting the horizontal-gap style. Much more extensible than looping over the dividers with getDivider yourself.
You can do this globally for all HDividedBoxs with a style like this:
HDividedBox { horizontal-gap: 3; divider-affordance: 1; divider-thickness: 1; }Or just a subset by setting a style name like so:
HDividedBox.mainViewHDividedBox { horizontal-gap: 3; divider-affordance: 1; divider-thickness: 1; }our HDividedBox would just need to have it’s stylename property set to mainViewHDividedBox like:
Thank you so much Peter, this is exactly what I was looking for. Your site are always helpful for my flex needs. Thank you!