On Fri, May 22, 2009 at 5:47 AM, lampei <lam...@gmail.com> wrote:
> Until recently, I did not know that you could reset the combobox back to the 
> "prompt" value by ctrl-clicking the value in the combobox dropdown.  However, 
> as most people don't know that this is a possiblity with the combobox, I'm 
> trying to mimic this functionality by setting the selectedIndex to -1 if a 
> person clicks (without the ctrl key) the same value that is already selected.
>
> I have yet to find the "selectedIndexChanged" property change to anything 
> other than false when the "change" event fires, so I'm unable to use that 
> (same for selectedItemChanged).  I tried setting the item under the mouse 
> when "itemRollOver" fires to a property, then set it to null when 
> "itemRollOut" fires.  Then when the person clicks, I said if the selectedItem 
> == the value underneath the mouse during itemRollOver, set the selectedIndex 
> = -1, however, the itemRollOut seems to fire before the click event is fired. 
>  I've also yet to find where the code is for the ctrl-left click, or what 
> causes that event to fire.
>

The code is in ListBase.as: the selectItem function (called from
mouseDownHandler).

            // allow unselecting via ctrl-click
            if (ctrlKey && selectedData[uid])
            {
                selectionChange = true;
                clearSelected(transition);
            }

Here's the solution.

 1.  Make a custom class, MyList.

public class MyList extends List
{
    override protected function selectItem(item:IListItemRenderer,
            shiftKey:Boolean, ctrlKey:Boolean,
            transition:Boolean = true):Boolean
    {
        var index:int = itemRendererToIndex(item);

        if (index == selectedIndex)
            ctrlKey = true;

        return super.selectItem(item, shiftKey, ctrlKey, transition);
    }
}

 2.  Use this class as the dropdown in the ComboBox.

  <mx:ComboBox id="cb" prompt="-- select --" dataProvider="{['1', '2', '3']}"
    dropdownFactory="{new ClassFactory(MyList)}" />

Tada!

Manish

-- 
www.manishjethani.com

Reply via email to