The following example shows how you can use the new Flex 4 DropDownList/ComboBox control to display a list of options.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.
For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/03/07/using-the-dropdownlist-in-flex-gumbo/ -->
<s:Application name="Spark_DropDownList_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx">
    <s:layout>
        <s:BasicLayout />
    </s:layout>
 
    <s:DropDownList id="dropDownLst"
            requireSelection="true"
            horizontalCenter="0" top="20">
        <s:dataProvider>
            <s:ArrayList source="[The,quick,brown,fox,jumps,over,the,lazy,dog]" />
        </s:dataProvider>
    </s:DropDownList>
 
</s:Application>

View source is enabled in the following example.

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

 
Tagged with:
 
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.

7 Responses to Using the DropDownList in Flex 4

  1. Hernan says:

    Hi, Why dont upload the example running like other examples

  2. Peter deHaan says:

    Hernan,

    The Gumbo posts will all need to be updated after the Fx prefix is removed. So I didn’t want to create/upload a bunch of SWFs and then recreate them all in the future. I’m planning on adding SWFs to these older examples (time permitting) when I update them all later after the big API renaming. For more information on the “Dropping the Fx Prefix” page on the Flex Gumbo page on the opensource.adobe.com website.

    Peter

  3. Tony says:

    Is there any way to set the dropdowns selected item based on a value? Basically i have name/value pairs and want to be able to set the dropdowns visibly selected item by value.

  4. Rajneesh says:

    Hi all,

    When I am placing this code on flex Builder . I am getting a Description Resource Path Location Type
    Unable to locate specified base class ‘spark.components.Application’ for component class ‘dropdownlist’. dropdownlist.mxml /brace-builder/src Unknown Flex Problem

    Kindly let me know the issue

    • Peter deHaan says:

      @Rajneesh,

      Are you targeting Flex SDK 4.0 or later? Also, possibly try renaming your MXML file something more unique than “dropdownlist.mxml”. That may be causing conflicts with the Spark DropDownList class.

      Peter

  5. jason says:

    Are there any tutorials here or elsewhere that describe how to skin all the elements of a DropDownList?
    Skin a scroll bar – piece of cake. But, I’m finding skinning a DropDownList extremely challenging.

    Thx.

  6. Shailen TJ says:

    Got same question as Jason and Hernan. We are in 2011 now. If you have some time, it would be great if you could create the examples in SWF format. Thank you very much.

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