Avg. Rating 2.7

Problem

You want to display icons in a Flex ComboBox control's dropdown menu.

Solution

The following example shows how you can specify a custom icon function on a Flex ComboBox control by setting the iconFunction property on the ComboBox control’s dropdown menu.

Detailed explanation

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/07/13/specifying-a-custom-icon-function-on-a-combobox-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            import mx.events.DropdownEvent;
 
            [Embed("assets/status_online.png")]
            private var statusOnline:Class;
 
            private function comboBox_open(evt:DropdownEvent):void {
                comboBox.dropdown.iconFunction = comboBoxDropdown_func;
            }
 
            private function comboBoxDropdown_func(item:Object):Class {
                if (item.hasOwnProperty("online") && item.online) {
                    return statusOnline;
                }
                return null;
            }
        ]]>
    </mx:Script>
   
    <mx:Array id="arr">
        <mx:Object label="One" online="true" />
        <mx:Object label="Two" />
        <mx:Object label="Three" online="true" />
        <mx:Object label="Four" />
        <mx:Object label="Five" />
        <mx:Object label="Six" />
        <mx:Object label="Seven" online="true" />
        <mx:Object label="Eight" />
        <mx:Object label="Nine" />
        <mx:Object label="Ten" />
    </mx:Array>
 
    <mx:ComboBox id="comboBox"
            dataProvider="{arr}"
            open="comboBox_open(event);" />
 
</mx:Application>

For more information, see "Specifying a custom icon function on a ComboBox control in Flex" at FlexExamples.com.

Report abuse

Related recipes