19
Aug
07

Creating a vertical LinkBar in Flex

I was playing around with the Flex LinkBar control this morning and somehow I never noticed it had a direction property. Well, it does, so I made a quick little app which filters an XML data provider based on which tab you’re on.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/19/creating-a-vertical-linkbar-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            [Bindable]
            [Embed(source="assets/bulletCheck.png")]
            public var BulletCheck:Class;

            [Bindable]
            [Embed(source="assets/bulletWarning.png")]
            public var BulletWarning:Class;

            [Bindable]
            [Embed(source="assets/bulletCritical.png")]
            public var BulletCritical:Class;
        ]]>
    </mx:Script>

    <mx:XML id="itemsXML">
        <items>
            <item label="Item 1" status="warning" />
            <item label="Item 2" status="critical" />
            <item label="Item 3" status="critical" />
            <item label="Item 4" status="check" />
            <item label="Item 5" status="warning" />
            <item label="Item 6" status="check" />
            <item label="Item 7" status="check" />
            <item label="Item 8" status="critical" />
        </items>
    </mx:XML>

    <mx:String id="CHECK">check</mx:String>
    <mx:String id="WARNING">warning</mx:String>
    <mx:String id="CRITICAL">critical</mx:String>

    <mx:XMLListCollection id="checkColl"
            source="{itemsXML.item.(@status == CHECK)}" />

    <mx:XMLListCollection id="warningColl"
            source="{itemsXML.item.(@status == WARNING)}" />

    <mx:XMLListCollection id="criticalColl"
            source="{itemsXML.item.(@status == CRITICAL)}" />

    <mx:HBox>
        <mx:LinkBar id="linkBar"
                direction="vertical"
                dataProvider="{viewStack}"
                themeColor="haloOrange" />

        <mx:ViewStack id="viewStack"
                width="200"
                height="120"
                backgroundColor="white">
            <mx:Canvas id="checkCanvas"
                    label="Success ({checkColl.length})"
                    icon="{BulletCheck}"
                    width="100%"
                    height="100%">
                <mx:DataGrid id="checkGrid"
                        dataProvider="{checkColl}"
                        width="100%"
                        height="100%" />
            </mx:Canvas>
            <mx:Canvas id="warningCanvas"
                    label="Warning ({warningColl.length})"
                    icon="{BulletWarning}"
                    width="100%"
                    height="100%">
                <mx:DataGrid id="warningGrid"
                        dataProvider="{warningColl}"
                        width="100%"
                        height="100%" />
            </mx:Canvas>
            <mx:Canvas id="criticalCanvas"
                    label="Critical ({criticalColl.length})"
                    icon="{BulletCritical}"
                    width="100%"
                    height="100%">
                <mx:DataGrid id="criticalGrid"
                        dataProvider="{criticalColl}"
                        width="100%"
                        height="100%" />
            </mx:Canvas>
        </mx:ViewStack>
    </mx:HBox>

</mx:Application>

View source is enabled in the following example.


4 Responses to “Creating a vertical LinkBar in Flex”


  1. 1 Bruce Aug 19th, 2007 at 10:18 am

    Very good example. I like how you created the XMLListCollection using MXML instead of ActionScript. Very easy to understand what is happening.

  2. 2 Pierre Aug 21st, 2007 at 7:14 am

    Nice realisation. I’m looking for to have the same effect than :
    http://weblogs.macromedia.com/khoyt/files/f1040.swf

    Can you give informations how it’s possible to have resizing panel like this, and the open and close panels.

    Thank

  3. 3 judah Oct 8th, 2007 at 12:22 pm

    Thank you! I didnt know about the direction property.

  4. 4 Jörg Mar 9th, 2008 at 7:30 pm

    Thank you very much!!!

    I searched for hours how to manage a vertical LinkBar…

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;".