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

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”.

8 thoughts on “Changing the Flex ComboBox control’s opening and closing easing functions

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

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

    does not work =(

    1. @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

  2. Hi,

    I have a problem that the spark combobox that i am using is not closing after selecting the item in dropdown.

    here is the correct scenario, I have 3 fixed labels in dropdown of combobox, when i click on the first label a pop up should appear( which contains yes and no buttons).clicking YES will send a blazeds call.the dropdown is not closing even after that popup closed .for rest of the labels there will not be any popups clicking on those. in that case the dropdown is closing.

    Thanks in advance.

    1. @naidu,

      Please file a bug at http://bugs.adobe.com/flex and include a simple test case and somebody from Adobe will take a look.
      Since you’re trying to launch a popup from a ComboBox change event, you may need to try manually closing the Spark ComboBox control using the close() method.

      Peter

Comments are closed.