Domanda

Does anyone know, is there any way to catch ItemClick Event in a Flex ComboBox (or anything similar). Maybe there's any trick .. :) I do realize, that I can customize it, but this not suits my case.

Thanks for your time :)

È stato utile?

Soluzione

As you can see in mx:ComboBox sources, the function, creating the dropdown list, is private, the listener to ITEM_CLICK is private and the list itself is also private:

private var _dropdown:ListBase;

private function getDropdown():ListBase
{
        // ...

        _dropdown = dropdownFactory.newInstance();

        // ...

        _dropdown.addEventListener(ListEvent.ITEM_CLICK, dropdown_itemClickHandler);

        // ....
}

private function dropdown_itemClickHandler(event:ListEvent):void
{
    if (_showingDropdown)
    {
        close();
    }
}

So you can not even extend ComboBox.

The only public thing is dropdownFactory, which theoretically can be overriden to somehow register the created dropdown list or create extended list. But the problem I see is that ComboBox is not the parent of dropdown list - PopupManager is. This can make dispatching (bubble) events quite difficult.

Altri suggerimenti

I think the following document will be helpful

ItemClick event in flex List

I found this solution. I just want a spark dropdownlist with itemClick event and without itemselect option (don't show selected item label on button)

[Event(name="itemClick", type="mx.events.ItemClickEvent")]

public class ItemClickDropDownList extends DropDownList
{

    public function ItemClickDropDownList()
    {
        super();
    }

    override public function closeDropDown(commit:Boolean):void
    {
        super.closeDropDown(commit);

        var e:ItemClickEvent = new ItemClickEvent(ItemClickEvent.ITEM_CLICK, true);
        e.item = this.selectedItem;
        e.index = this.selectedIndex;
        dispatchEvent(e);

        //Deselect item
        this.selectedIndex = -1;
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top