27
Aug
07

Adding icons to a Flex Accordion control

The following example demonstrates how you can add embedded icons to a Flex Accordion container.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/27/adding-icons-to-a-flex-accordion-control/ -->
<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")]
            private var BulletCheck:Class;

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

            [Bindable]
            [Embed(source="assets/bulletCritical.png")]
            private 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:ApplicationControlBar dock="true">
        <mx:Label text="selectedIndex: {accordion.selectedIndex}" />
        <mx:Spacer width="100" />
        <mx:Label text="label: {accordion.getHeaderAt(accordion.selectedIndex).label}" />
    </mx:ApplicationControlBar>

    <mx:Accordion id="accordion"
            width="400"
            height="200">
        <mx:VBox label="Success"
                icon="{BulletCheck}"
                width="100%"
                height="100%">
            <mx:DataGrid id="successGrid"
                    dataProvider="{itemsXML.item.(@status == 'check')}"
                    width="100%"
                    height="100%">
            </mx:DataGrid>
        </mx:VBox>

        <mx:VBox label="Warning"
                icon="{BulletWarning}"
                width="100%"
                height="100%">
            <mx:DataGrid id="warningGrid"
                    dataProvider="{itemsXML.item.(@status == 'warning')}"
                    width="100%"
                    height="100%">
            </mx:DataGrid>
        </mx:VBox>

        <mx:VBox label="Critical"
                icon="{BulletCritical}"
                width="100%"
                height="100%">
            <mx:DataGrid id="criticalGrid"
                    dataProvider="{itemsXML.item.(@status == 'critical')}"
                    width="100%"
                    height="100%">
            </mx:DataGrid>
        </mx:VBox>
    </mx:Accordion>

</mx:Application>

View source is enabled in the following example.


1 Response to “Adding icons to a Flex Accordion control”


  1. 1 Jader May 24th, 2008 at 11:05 pm

    I really like this simple example of adding icons to an Accordion.
    Very helpful!

    Would you know how to change the behavior of an Accordion?
    I am trying to figure out a way to customize an Accordion so that the VBoxes inside will remain open unless I click a triangle icon that I place on the VBox.
    Perhaps an Accordian is not what I really want to use, but so far, it seems like an Accordion has everything I want, except that it only allows one page, or VBox, to be open at a time.
    Do you have any ideas on how to override the behavior of an Accordion so that it only opens and closes each section when I call that event? (Also, what event would I call?)

    Thanks in advanced!
    L. Jay Adams

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