Accordion with Icons
![]()
I built this component to allow an icon to be added to each Accordion Header where the icon is dependent on the current state of the Accordion. There are 3 possible states that are tracked, up, down, and selected. The upIcon is displayed whenever the pane is above the selected pane. The downIcon is displayed whenever the pane is below the selected pane. The selectedIcon is displayed when pane is the selected pane. See the image below.
![]()
Sample Syntax (Basic with default icons):
- <eflex:AccordionIcons>
- <mx:Canvas label=”Canvas”/>
- <mx:VBox label=”VBox”/>
- <mx:HBox label=”HBox”/>
- </eflex:AccordionIcons>
Sample Syntax (Advanced with custom icons and selectedIndex):
- <eflex:AccordionIcons
- upIcon=”@Embed(source=’assets/icons/arrowUp2.gif’)”
- downIcon=”@Embed(source=’assets/icons/arrowDown2.gif’)”
- selectedIcon=”@Embed(source=’assets/icons/arrowSelected2.gif’)” height=”200″
- selectedIndex=”1″>
- <mx:Canvas label=”Canvas”/>
- <mx:VBox label=”VBox”/>
- <mx:HBox label=”HBox”/>
- </eflex:AccordionIcons>



March 29th, 2007 at 10:12 am
Very nice.
March 29th, 2007 at 10:49 am
Rich,
Cool Component!
When I run the demo, it seems like my browser refreshes. The component maintains state, however. Is this the intended functionality?
dw
March 29th, 2007 at 10:51 am
That would be the history manager at work. You can use your forward and back keys to change the Accordion state. This is the default behavior of the history manager.
March 30th, 2007 at 3:28 am
LOVE this component - makes the Accordion look much more interesting! Thanks for this!
Jamie.
March 31st, 2007 at 12:04 am
hey man…way to go!
April 3rd, 2007 at 12:55 pm
So there is a minor problem when you set selectedFillColors and textRollOverColor. The icons go away while in the selected and rollover states. I’m guessing they need to be accounted for when an updatedisplay happens. I havn’t had time to look into the real reason yet.
April 3rd, 2007 at 1:17 pm
Actually I take that back. My browser cached that. It has more to do with setting these skins in a stylesheet instead of inline. I’m using a Type selector in my stylesheet.
April 19th, 2007 at 11:35 am
Hi, great work, just one minor problem happened when i was using the component in this way:
1) i started the Flex application in one state and then the AccordionIcon component was only present in another state to which i changed later (currentState=nextState).
With this behaviour the this.getChildDescriptors().length returns null, i don’t know why, even the childrenCreated is called OK.
Anyway i changed it with this.getChildren().length and now it works fine.
Gregor
May 25th, 2007 at 3:53 am
Cool stuff. Thx
July 4th, 2007 at 1:48 pm
Great Job, but i have a little problem.
I need assign a different icon for each header of the accordion.
That can be posibly ? Can you help me?
July 5th, 2007 at 11:16 am
Yes, you could either just add the icon to the container that you are using within your Accordion menu like this:
Or you can do it with ActionScript:
October 4th, 2007 at 9:21 am
Thanks for the great tips!
A must read for all the users out there!
October 18th, 2007 at 1:27 pm
Hey thank you that is exactly what is was searching for for my site. Will try it and hopefully have no problem with it…
November 5th, 2007 at 5:58 pm
First, thanks for the component.
I can get it to work great when the child containers added to AccordionIcons via MXML (like the example shown on this blog). However, when the child containers are added via ActionScript, then something goes seriously wrong with the initialization of the application. (I don’t yet know what exactly goes wrong… in my case, the panel in which the AccordionIcons component is placed is completely blank.)
The MXML is:
I add children to the AccordionIcons component in popAccChildren(). I am adding several Canvas containers, e.g.:
var c:Canvas = new Canvas();
c.percentWidth = 100;
c.percentHeight = 100;
c.label = “Label 01″;
prodAccordion.addChild(c);
I have tried calling popAccChildren() on occurrence of different events like “initialize”, “creationComplete”, etc…. nothing I have tried has worked.
If I switch to using mx.containers.Accordion instead, everything works just fine.
Any idea what is going wrong or do you have any example?
Thanks!
November 6th, 2007 at 8:19 am
Try this again (using square brackets instead of angle brackets)…
The MXML is:
[eflex:AccordionIcons id=”prodAccordion” initialize=”popAccChildren()” …]
[/eflex:AccordionIcons]
November 6th, 2007 at 10:34 am
Figured it out…. in the method AccordionIcons.setIcons, there is a call to this.childDescriptors. It seems this field is only set when child components are added via MXML. I would think this.childDescriptors.length would simple return zero when child components are added via ActionScript, but it seems some sort of exception occurs. Anyhow, calling numChildren instead of childDescriptors resolves the problem.
November 6th, 2007 at 10:53 am
Thanks Chris,
I have updated the source code.
January 3rd, 2008 at 12:51 pm
Thank you for the component. It is much better than the plain accordion which can look confusing without the graphics.
I have an additional problem. I want to use your component to show up/down/selected but I also want an additional icon that goes with my label. For example, where you have the word “Canvas” for the Canvas label, I want a graphic followed by my text (I am showing logging messages and want graphics to display for success, error, etc).
But it appears that I can only have 1 icon for a container which means I have to choose between my message graphic or your navigation graphic. Do you know of a way to have both?
Thanks again!
January 6th, 2008 at 1:17 pm
This script is cool..
But, I’m really confused about a few lines
Namely, line 127 of of AccordionIcons.as
Why must you import mx.core.Container when AccordionIcons extends Accordion which extends Container? So all the properties of Container should be inherited by AccordionIcons.
You don’t have to cast it to a Container, is this correct?
January 6th, 2008 at 1:46 pm
And I even tried :
Accordion (this.getChildAt(i)).icon = upIcon;
But that gave a run time error:
“Type Coercion failed: cannot convert mx.containers::Canvas@6fd80a1 to mx.containers.Accordion.”
I’m not sure what is happening there either. I thought that would have worked too
January 6th, 2008 at 8:10 pm
Casting it as a container allows the icon to be set as initially the object type is DisplayObject. Can you send me your source code that is throwing the error? rtretola AT gmail.com
May 29th, 2008 at 9:32 am
Hi everythingflex
Your custom accordion is great. Actually I want to add icon in my accordion on the right side of the label instead of left. Is there any way to do that.
Any help from your side will be appreciated.
Thanx
June 16th, 2008 at 5:10 pm
Thanks for the great example.
I have a problem. the sample accordion didn’t work when i use a style sheet. Is there an issue with the style sheet and flex accordion? Thanks.