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

 
About The Author

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.

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

  1. JCKodel says:

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

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

    does not work =(

    • Peter deHaan says:

      @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

    • Peter deHaan says:

      @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

  2. Anonymous says:

    “after the jump” sucks balls.

  3. Arkady says:

    how to set openDuration at spark components?

  4. naidu says:

    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.

Leave a Reply

Your email address will not be published.

You may 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