Sometimes a ComboBox with icons in the list as well as in the text display area can be useful. However the out of the box Flex ComboBox component dosn’t support this. Here is one way of doing it.

IconComboBox2

Basically I’ve extended the existing ComboBox adding iconField and iconFunction properties. I had to instance my own ClassFactory for the internal list that is used as the dropdown so that I could pre-initialize the required properties. I override the measuredWidth so that I can make room for the icon, and adjust the x position of the internal textInput to compensate.

A little addition to the toolbox that can come in really handy.

Sample and Source : IconComboBox

Enjoy.

Jason Hawryluk

7 Responses to “Flex 2.0.1 ComboBox with icon support.”

  1. flexpaul Says:

    When I click view source and it goes to delicious. what’s happening?

  2. flexibleexperiments Says:

    Seems to be working fine here? Weird.
    Anyone else having trouble ?

    jason

  3. eightlines Says:

    View Source appears to be working fine here. Thanks for the code!

  4. Code Sweat Blog » Blog Archive » Some Flex 2 Related Links (pt. two) Says:

    […] Flex 2.0.1 ComboBox with icon support. « Flexible Experiments […]

  5. Ben Holloway Says:

    Source link seems to be not working

  6. flexibleexperiments Says:

    Seems to be working for me.

    Ben, try again, and let me know.

    Jason

  7. Jeoren Says:

    Do you have embed the icons? I need to load them dynamically. But it keeps throwing an error in measuredWidth (null object reference)


    var l:String = element.@nld+” - “+element.@nom;
    var ic:String = “images/flags/”+String(element.@nld).toLowerCase()+”.png”; trace(ic);
    countryArr[cntr] = {label:l, data:ic};

Leave a Reply