I recently had a design comp that required the icon of the Accordion header to be positioned a few pixels from the right.
![]()
The edits were pretty simple in order to get this working as a proof of concept. What follows is a bunch of geeky code stuff so if you have an aversion to code then go to my other blog and look at pretty pictures
Solution after the jump
First you need to subclass ##mx.controls.AccordionHeader which is a subclass of
mx.controls.ButtonSecond add an import for the mx_internal namespace:
import mx.core.mx_internal;
use namespace mx_internal;Next override the updateDisplayList function, and add your icon positioning code in there. I added some conditional logic that only puts the icon on the right hand side if it is specified by a
iconPosition: right;update display method:
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList( unscaledWidth, unscaledHeight );
if( getStyle("iconPosition") == "right" )
{
currentIcon.x = this.unscaledWidth - currentIcon.width - ( getStyle("iconPadding") != null ? getStyle("iconPadding") : 15 );
}
}This handles the AccordionHeader part of the problem, but now we need it to render in the Accordion itself soo.
Subclass
mx.controls.Accordionpublic function AccordionRounded()
{
super();
headerRenderer = new ClassFactory( AccordionHeaderPositionableIcon );
}Finally I added the style declaration for iconPosition in AccordionHeaders style decleration in the style sheet.
AccordionHeader
{
icon: Embed(source='icons.swf', symbol='btn_accordRight');
selectedOverIcon: Embed(source='icons.swf', symbol='btn_accordDown');
selectedUpIcon: Embed(source='icons.swf', symbol='btn_accordDown');
selectedDownIcon: Embed(source='icons.swf', symbol='btn_accordDown');
skin: Embed(skinClass="AccordionHeader_skin");
iconPosition: right;
iconPadding: 20;
}Add your custom component to the display list and you should see your icon now on the right hand side of the AccordionHeader instead of the left as default.

4 days later:
Hi Kristofer,
Great article. Do you have a sample demo and source available?
Thanks,
Jason
2 months later:
Sweet. Thanks for sharing :)
8 months later:
Dark site.. not used friendly..