10
Oct
08

Setting the vertical divider cursor on a VDividedBox container in Flex

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 Response to “Setting the vertical divider cursor on a VDividedBox container in Flex”


  1. 1 GG Oct 11th, 2008 at 1:42 am

    like always, just big thx….

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed