OK, I admit that this post probably doesn’t have much real-world use, and can probably annoy users if implemented poorly, but if you’ve ever wondered how/if you can change the opening/closing duration or easing function used for a ComboBox dropdown menu, this post is for you!
This entry looks at customizing the ComboBox control’s openDuration and closeDuration styles which control how long it takes for the dropdown menu to appear or disappear. By default both of these styles are set to 250 milliseconds (1/4 second). We’ll also look at changing the easing method used to animate the dropdown menu. Finally, we look at explicitly setting the dropdown menu’s width so it doesn’t inherit the ComboBox’s width and alternate the row colors for the items in the dropdown.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2007/08/18/changing-the-flex-combobox-controls-opening-and-closing-easing-functions/ --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white"> <mx:Script> <![CDATA[ import mx.effects.easing.*; ]]> </mx:Script> <mx:ComboBox id="comboBox" openDuration="1000" openEasingFunction="Bounce.easeOut" closeDuration="1000" closeEasingFunction="Bounce.easeIn" prompt="Please select an item..." selectedIndex="-1" dropdownWidth="150" alternatingItemColors="[0xDFDFDF, 0xEEEEEE]"> <mx:dataProvider> <mx:Array> <mx:Object label="Item 1" /> <mx:Object label="Item 2" /> <mx:Object label="Item 3" /> <mx:Object label="Item 4" /> <mx:Object label="Item 5" /> <mx:Object label="Item 6" /> <mx:Object label="Item 7" /> <mx:Object label="Item 8" /> </mx:Array> </mx:dataProvider> </mx:ComboBox> </mx:Application>
View source is enabled in the following example.
For an example of setting the openEasingFunction and closeEasingFunction styles in a <Style/> block in Flex 4, see “Changing the opening and closing easing functions on a Halo ComboBox control in Flex 4″.

{ 5 comments… read them below or add one }
How to accomplish this using CSS (I want to make the easingXXXFunction application-wide)?
ComboBox { openEasingFunction: ClassReference(fullNamespace.Bounce.Style); }does not work =(
@JCKodel,
Unfortunately, I do not believe that syntax is supported by the Flex compiler.
But, I do have a few other workarounds you could try:
1) Use the StyleManager to globally override the easing functions for all ComboBox controls:
– or –
2) Extend the ComboBox control and specify the
openEasingFunctionstyle in the MXML. Then you can use the custom ComboBox control and still just change the openEasingFunction style in one place and have it change all ComboBox controls in your entire site.And the custom ComboBox component, comps/CustomComboBox.mxml, is as follows:
Hope that helps,
Peter
@JCKodel,
It turns out you CAN set the
openEasingFunctionandcloseEasingFunctionin CSS, but it was a compiler feature added in the new Flex 4 SDK. For more information, and an example, see “Changing the opening and closing easing functions on a Halo ComboBox control in Flex 4″.Peter
“after the jump” sucks balls.
??