ItemClick Event in a flex Combobox

青春壹個敷衍的年華 提交于 2019-12-11 19:57:23

问题


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 :)


回答1:


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.




回答2:


I think the following document will be helpful

ItemClick event in flex List




回答3:


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;
    }


来源:https://stackoverflow.com/questions/7267982/itemclick-event-in-a-flex-combobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!