The following example shows how you can customize the divider skin on a Flex HDividedBox or VDividedBox container by setting the dividerSkin style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/18/customizing-the-divider-skin-on-a-dividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_dividerSkin_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:HDividedBox id="dividedBox"
            dividerSkin="@Embed('assets/DividedBox.png')"
            horizontalGap="24"
            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 dividerSkin style in an external .CSS file or <mx:Style /> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/18/customizing-the-divider-skin-on-a-dividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_dividerSkin_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        HDividedBox {
            dividerSkin: Embed("assets/DividedBox.png");
            horizontalGap: 24;
        }
    </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 dividerSkin style using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/18/customizing-the-divider-skin-on-a-dividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_dividerSkin_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();">

    <mx:Script>
        <![CDATA[
            [Embed("assets/DividedBox.png")]
            private const customDividerSkin:Class;

            private function init():void {
                dividedBox.setStyle("dividerSkin", customDividerSkin);
            }
        ]]>
    </mx:Script>

    <mx:HDividedBox id="dividedBox"
            horizontalGap="24"
            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:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/18/customizing-the-divider-skin-on-a-dividedbox-container-in-flex/ -->
<mx:Application name="HDividedBox_dividerSkin_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();">

    <mx:Script>
        <![CDATA[
            import mx.containers.Box;
            import mx.containers.HDividedBox;

            [Embed("assets/DividedBox.png")]
            private const customDividerSkin:Class;

            private var dividedBox:HDividedBox;
            private var box1:Box;
            private var box2:Box;

            private function init():void {
                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.setStyle("dividerSkin", customDividerSkin);
                dividedBox.setStyle("horizontalGap", 24);
                dividedBox.addChild(box1);
                dividedBox.addChild(box2);
                addChild(dividedBox);
            }
        ]]>
    </mx:Script>

</mx:Application>
 
Tagged with:
 
About The Author

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.

One Response to Customizing the divider skin on a DividedBox container in Flex

  1. Actually, coming from a html/css/javascript background – I think it’s great that you first and foremost show MXML examples :-) I love the simplicity.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree