Changing the Flex ComboBox control’s opening and closing easing functions

by Peter deHaan on August 18, 2007

in ComboBox

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 }

1 JCKodel August 3, 2009 at 4:17 pm

How to accomplish this using CSS (I want to make the easingXXXFunction application-wide)?

ComboBox
{
    openEasingFunction: ClassReference(fullNamespace.Bounce.Style);
}

does not work =(

Reply

2 Peter deHaan August 3, 2009 at 7:07 pm

@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:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        initialize="init();">
 
    <mx:Script>
        <![CDATA[
            import mx.effects.easing.Bounce;
 
            private function init():void {
                var styObj:CSSStyleDeclaration = StyleManager.getStyleDeclaration("ComboBox");
                styObj.setStyle("openEasingFunction", Bounce.easeOut);
            }
        ]]>
    </mx:Script>
 
    <mx:ComboBox id="cb1"
            dataProvider="[The,Quick,Brown,Fox,Jumps,Over,The,Lazy,Dog]"
            openDuration="2000" />
 
    <mx:ComboBox id="cb2"
            dataProvider="[The,Quick,Brown,Fox,Jumps,Over,The,Lazy,Dog]"
            openDuration="2000" />
 
</mx:Application>

– or –

2) Extend the ComboBox control and specify the openEasingFunction style 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.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        xmlns:comps="comps.*">
 
    <comps:CustomComboBox id="customCB"
            dataProvider="[The,Quick,Brown,Fox,Jumps,Over,The,Lazy,Dog]"
            openDuration="2000" />
 
</mx:Application>

And the custom ComboBox component, comps/CustomComboBox.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml" openEasingFunction="Bounce.easeOut">
 
    <mx:Script>
        import mx.effects.easing.Bounce;
    </mx:Script>
 
</mx:ComboBox>

Hope that helps,
Peter

Reply

3 Peter deHaan August 5, 2009 at 7:23 am

@JCKodel,

It turns out you CAN set the openEasingFunction and closeEasingFunction in 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

Reply

4 Anonymous January 27, 2010 at 4:10 pm

“after the jump” sucks balls.

Reply

5 Peter deHaan January 27, 2010 at 5:53 pm

??

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: