Creating a simple Flex Accordion inline header renderer

by Peter deHaan on September 24, 2007

in Accordion, Button

The following example shows how you can create a simple, inline header renderer in Flex which uses the Button control for a Flex Accordion header.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/24/creating-a-simple-flex-accordion-inline-header-renderer/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            [Bindable]
            [Embed(source="assets/Accordion.png")]
            private var AccordionIcon:Class;

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

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

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

            [Bindable]
            [Embed(source="assets/ControlBar.png")]
            private var ControlBarIcon:Class;
        ]]>
    </mx:Script>

    <mx:Accordion id="accordion" backgroundAlpha="0.0"
            height="100%"
            width="100%"
            headerHeight="32"
            borderStyle="none"
            historyManagementEnabled="false">
        <mx:headerRenderer>
            <mx:Component>
                <mx:Button fontWeight="normal"
                        labelPlacement="left"
                        textAlign="left"
                        cornerRadius="{outerDocument.accordion.getStyle('headerHeight')/2}" />
            </mx:Component>
        </mx:headerRenderer>

        <mx:VBox label="Accordion"
                icon="{AccordionIcon}">
            <mx:Label text="The quick brown fox..." />
        </mx:VBox>

        <mx:VBox label="ApplicationControlBar"
                icon="{ApplicationControlBarIcon}">
            <mx:Label text="The quick brown fox..." />
        </mx:VBox>

        <mx:VBox label="Box"
                icon="{BoxIcon}">
            <mx:Label text="The quick brown fox..." />
        </mx:VBox>

        <mx:VBox label="Canvas"
                icon="{CanvasIcon}">
            <mx:Label text="The quick brown fox..." />
        </mx:VBox>

        <mx:VBox label="ControlBar"
                icon="{ControlBarIcon}">
            <mx:Label text="The quick brown fox..." />
        </mx:VBox>
    </mx:Accordion>

</mx:Application>

View source is enabled in the following example.

{ 4 comments… read them below or add one }

1 Tony Fendall September 24, 2007 at 2:24 pm

If I were to create my renderer in a seperate class would I still be able to use the tag, and thus the outerDocument property? Or is this limited to inline renderers?

Reply

2 melaine November 29, 2007 at 4:51 am

Hi !

For me icons are on the right !!!!! with the same full code. WHY ?

Thanks
Melaine

Reply

3 Prashanth Samanth June 10, 2008 at 5:23 am

I want a simple Button Dropdown

Ex: when I click the button, the drop down should be having two more option, so when I click the first button it should pop a Alert Box, and when I click the Second option it should open a Popup..

Please help me to get the solution for this

Thanks
Prashanth Samanth

Reply

4 Tom June 10, 2009 at 11:59 pm

Hi, why the Flex team fixed the header class to the Button class?

I had to copy/paste all the ***** code of the Accordion.as file to remove all the casts to Button in order to have a HBox in my accordion Header ;-)

http://www.ebuildy.com/adobe-flex/creer-un-custom-accordion-header/

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: