Toggling item roll over highlighting on a ComboBox control in Flex

by Peter deHaan on July 7, 2008

in ComboBox

The following example shows how you can toggle the item roll over hightlighting on a Flex ComboBox control’s dropdown menu by setting the useRollOver style using ActionScript or CSS.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/07/07/toggling-item-roll-over-highlighting-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;

            private function comboBox_open(evt:DropdownEvent):void {
                comboBox.dropdown.setStyle("useRollOver", checkBox.selected);
            }
        ]]>
    </mx:Script>

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />
        <mx:Object label="Five" />
        <mx:Object label="Six" />
        <mx:Object label="Seven" />
        <mx:Object label="Eight" />
        <mx:Object label="Nine" />
        <mx:Object label="Ten" />
    </mx:Array>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="useRollOver:">
                <mx:CheckBox id="checkBox" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:ComboBox id="comboBox"
            dataProvider="{arr}"
            open="comboBox_open(event);" />

</mx:Application>

View source is enabled in the following example.

You can also set the useRollOver style in an external .CSS file or <mx:Style /> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/07/07/toggling-item-roll-over-highlighting-on-a-combobox-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:Style>
        ComboBox {
            dropdownStyleName: myComboBoxDropdownStyles;
        }

        .myComboBoxDropdownStyles {
            useRollOver: false;
        }
    </mx:Style>

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />
        <mx:Object label="Five" />
        <mx:Object label="Six" />
        <mx:Object label="Seven" />
        <mx:Object label="Eight" />
        <mx:Object label="Nine" />
        <mx:Object label="Ten" />
    </mx:Array>

    <mx:ComboBox id="comboBox"
            dataProvider="{arr}" />

</mx:Application>

{ 4 comments… read them below or add one }

1 Tangent July 8, 2008 at 4:22 am

This is an interesting sample, though I must admit that usability is worse without the rollover, hence I could hardly think of any useful scenarios that would take advantage of this feature.

Reply

2 Adam July 8, 2008 at 10:08 am

@Tangent
The rollover is off by default, so yes, the usability is reduced by default. Turning the rollover style ON is what’s important about this style setting.

Reply

3 mp3 indir July 13, 2008 at 12:52 am

I just found this site. I really like your samples. Can we use it in our web sites ?

Reply

4 Photoshop July 13, 2008 at 3:37 am

An interesting example, try to benefit from it

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

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

Previous post:

Next post: