Setting the vertical divider cursor on a VDividedBox container in Flex

by Peter deHaan on October 10, 2008

in VDividedBox

In a previous example, “Setting the horizontal divider cursor on an HDividedBox container in Flex”, we saw how to set a horizontal divider cursor on a Flex HDividedBox container by setting the horizontalDividerCursor style.

The following example shows how you can set a vertical divider cursor on a Flex VDividedBox container by setting the verticalDividerCursor style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/10/10/setting-the-vertical-divider-cursor-on-a-vdividedbox-container-in-flex/ -->
<mx:Application name="VDividedBox_verticalDividerCursor_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:VDividedBox id="vDividedBox"
            verticalDividerCursor="@Embed('assets/arrow_refresh.png')"
            width="100%"
            height="100%">
        <mx:HBox backgroundColor="haloGreen"
                width="100%"
                height="100%">
        </mx:HBox>
        <mx:HBox backgroundColor="haloBlue"
                width="100%"
                height="100%">
        </mx:HBox>
    </mx:VDividedBox>

</mx:Application>

View source is enabled in the following example.

You can also set the verticalDividerCursor style using 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/10/10/setting-the-vertical-divider-cursor-on-a-vdividedbox-container-in-flex/ -->
<mx:Application name="VDividedBox_verticalDividerCursor_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        VDividedBox {
            verticalDividerCursor: Embed("assets/arrow_refresh.png");
        }
    </mx:Style>

    <mx:VDividedBox id="VDividedBox"
            width="100%"
            height="100%">
        <mx:HBox backgroundColor="haloGreen"
                width="100%"
                height="100%">
        </mx:HBox>
        <mx:HBox backgroundColor="haloBlue"
                width="100%"
                height="100%">
        </mx:HBox>
    </mx:VDividedBox>

</mx:Application>

Or, you can set the verticalDividerCursor style using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/10/10/setting-the-vertical-divider-cursor-on-a-vdividedbox-container-in-flex/ -->
<mx:Application name="VDividedBox_verticalDividerCursor_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

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

            private function vDividedBox_init():void {
                vDividedBox.setStyle("verticalDividerCursor", ArrowRefreshIcon);
            }
        ]]>
    </mx:Script>

    <mx:VDividedBox id="vDividedBox"
            width="100%"
            height="100%"
            initialize="vDividedBox_init();">
        <mx:HBox backgroundColor="haloGreen"
                width="100%"
                height="100%">
        </mx:HBox>
        <mx:HBox backgroundColor="haloBlue"
                width="100%"
                height="100%">
        </mx:HBox>
    </mx:VDividedBox>

</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/10/10/setting-the-vertical-divider-cursor-on-a-vdividedbox-container-in-flex/ -->
<mx:Application name="VDividedBox_verticalDividerCursor_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();">

    <mx:Script>
        <![CDATA[
            import mx.containers.HBox;
            import mx.containers.VDividedBox;

            [Embed("assets/arrow_refresh.png")]
            private const ArrowRefreshIcon:Class;

            private var vDividedBox:VDividedBox;
            private var hBox1:HBox;
            private var hBox2:HBox;

            private function init():void {
                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");

                vDividedBox = new VDividedBox();
                vDividedBox.percentWidth = 100;
                vDividedBox.percentHeight = 100;
                vDividedBox.addChild(hBox1);
                vDividedBox.addChild(hBox2);
                vDividedBox.setStyle("verticalDividerCursor",
                            ArrowRefreshIcon);
                addChild(vDividedBox);
            }
        ]]>
    </mx:Script>

</mx:Application>

{ 1 comment… read it below or add one }

1 GG October 11, 2008 at 1:42 am

like always, just big thx….

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: