Creating a vertical LinkBar in Flex

by Peter deHaan on August 19, 2007

in Canvas, LinkBar, ViewStack

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.

{ 6 comments… read them below or add one }

1 Bruce August 19, 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.

Reply

2 Pierre August 21, 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

Reply

3 judah October 8, 2007 at 12:22 pm

Thank you! I didnt know about the direction property.

Reply

4 Jörg March 9, 2008 at 7:30 pm

Thank you very much!!!

I searched for hours how to manage a vertical LinkBar…

Reply

5 Adrian November 29, 2008 at 11:41 pm

Now how about having 2 or 3 link bars with items each with view stacks an passing from one to another link bar selecting and deselected the activ tab???

Thant is something that is bugging me….

Reply

6 Manoj Sinha December 2, 2008 at 1:45 am

Hi,
I am facing a problem of data binding. I am using web service to fill a grid, in the web method I have to pass two parameters, it will return result of xml document. The same I want to fill in a DataGrid using Adobe Flex Buiider 3.

Please help me..its urgent

Sample.mxml

{_txtuserid.text}

{_txtpassword.text}

{token.text}

After login..i want to fill the result in the datagrid. I am using Sql as backend and Asp dot net pattern for coding in Adobe.

Help me in doing the same
thanks in advance

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: