Setting styles on individual Flex Accordion headers
Loyal reader, Madhu, asked the following question the other day:
Is it possible to color individual headers of the accordion?
Well, I played around with it briefly this evening and it seems that you can get individual accordion headings using the Accordion class’s getHeaderAt() method, then it is just a matter of saving that reference in a variable, or applying a style directly to the returned Button reference.
The example itself is pretty simple, but I’m sure the same principles apply to other styles as well.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/10/30/setting-styles-on-individual-flex-accordion-headers/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Style>
AccordionHeader {
fillColors: black, black;
fillAlphas: 1, 1;
textRollOverColor: white;
textSelectedColor: white;
themeColor: black;
}
</mx:Style>
<mx:Script>
<![CDATA[
private function init():void {
accordion.getHeaderAt(0).setStyle("color", "red");
accordion.getHeaderAt(1).setStyle("color", "haloOrange");
accordion.getHeaderAt(2).setStyle("color", "yellow");
accordion.getHeaderAt(3).setStyle("color", "haloGreen");
accordion.getHeaderAt(4).setStyle("color", "haloBlue");
}
]]>
</mx:Script>
<mx:Accordion id="accordion"
width="300"
height="200"
creationComplete="init();">
<mx:VBox label="Red" />
<mx:VBox label="Orange" />
<mx:VBox label="Yellow" />
<mx:VBox label="Green" />
<mx:VBox label="Blue" />
</mx:Accordion>
</mx:Application>
View source is enabled in the following example.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
19 Responses to Setting styles on individual Flex Accordion headers
Leave a Reply Cancel reply
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


Hello,
Is it possible to do the same thing with children instead of headers in the accordion ?
Thanx
Hi,
The children (VBox) can be styled with their own styles.
.box1Style { backgroundColor: #ff0000; }Hi. I have a question. Is it posible that when you click on a header already open it closes? And to all the headers appear closed in the initial state?
Thanks, sorry about my english ^^u
I have the same question as GuitarWorker. I’ve used Scriptaculous for this purpose: click on a header the accordion expands, click on the same header the accordion contracts. I’m brand-spanking new to FLEX and want to learn how to do this type of work. Any help on this matter would be most appreciated!! Also, as GuitarWorker mentioned, how do you code for the headers to be closed on page load? Thank you!
P.S. Your efforts are well received and appreciated. It is great to have someone leading the way with examples.
Nice Example. I have found lots of great stuff on your site.
Thanks so much for this example… i too keep finding great examples here on this site!
Hmmm…I escaped my code, but it still seems to not have displayed:
I want to change the header button colors on an Accordion inside of a Repeater and when I try to do the “getHeaderAt” it just returns null. You can see the code at:
http://docs.google.com/Doc?id=dc2gtjz3_16hbx4rfgj
By the way, your blog is saving my life! I just started with Flex two days ago for a company project and your examples have been hugely helpful! Thanks so much!
.:Joshua
Old blog post I know, but helpful for people finding it now:
Instead of setting individual setStyle for everything you want to change, create a style with a name and do the following.
accordian.getHeaderAt(0).setStyle(“styleName”,”yourStyleNameFromCSS”);
It’s what I want to know! Thanx! :-)
Ciao to everybody…
i have a problem with accordation header, i want use how header an image that is different from the others, one image for one voice of menu.
How i can customize this accordation menu? i will use horizontal Accordation.
Can we help me?
Ciao, grazieeee
@luigi russo,
I’d do something like the example above, except set the
skinstyle to an embedded image instead of thecolorstyle.Something similar to the following:
Peter
Accordion sorry for my english
Grazieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee PETER
It works very well
Thanks Thanks thanks ciaooo
Hello Peter,
how are u?
I have a question: Can i use prettyphoto of jquery in flex?
prettyphoto is very nice, how i can use it in flex?
Grazie ciaooo
@luigi,
I’ve never used AJAX/jQuery/”prettyphoto”, but you could try using the ExternalInterface class to call some JavaScript from your Flex app. I think I had a comment/complaint earlier in my blog though about that approach not always working with AJAX though. But it may depend on your specific AJAX framework/implementation/code.
Apart from that, you may be able to create your own similar photo library in Flex using ActionScript 3.0 and the PopUpManager, and a custom Panel and other stuff.
You’d probably have better luck asking on a high volume mailing list like flexcoders and see what other people are using.
Peter
Hy,
I try to add a background image to headers but it doesn’t work… why please ?
Peter,
Is it possible to have different header heights for each of the header in an Accordion?
I tried this, it doesnt work :
Accordion.getHeaderAt(0).setStyle(“headerheight”, 75);
Any idea how we can do this?
Regards,
Praveen.G
I am having the same problem with header heights i can adjust the heights at run time by creating custom header renderer but i need to make the headers different size (match content) any ideas ??
Great post btw :-)
Is there a way to create a custom item renderer for the accordion label?
Say if I wanted a string as the label but different colors for different words in the label
like in black Goals: then if they are met have green text beside that or not met red text