我有一個組合框可以作爲搜索應用程序的自我暗示。搜索功能正在通過搜索按鈕觸發。我還希望在組合框中的項目是雙擊或單擊時觸發搜索功能。代碼:AS3,如何在組合框中選擇項目時觸發搜索功能?
//for triggering search function from combobox(search_complex) it will be
something like that but i am not sure
search_complex.addEventListener(Event.CHANGE, search);
search(event:Event):void{//something will come hereto use "selctedItem" to
trigger search function}
//search function which is working fine by pressing search button
bt_search.addEventListener(MouseEvent.CLICK, search);
function search(MouseEvent):void{
currentUserbase = [];
for (var n:int = 0; n<allUserbase.length; n++)
{
for (var k:int = 0; k<allUserbase[n].complex.length; k++)
{
if ((allUserbase[n].complex[k].value.toLowerCase() ==
search_complex.text.toLowerCase() || search_complex.text==""))
{
currentUserbase.push(allUserbase[n]);
}
}
}
updateList();
}//end search
@jason,感謝回答,但如果和如何使用search_complex.selectedItem.label怎麼這樣,當我在組合框中選擇一個項目,就會觸發「搜索」功能 – hanna 2011-03-03 16:38:55
@hanna,假設'search'是實際執行搜索的函數,只要單擊'bt_search'按鈕或從'search_complex combobox'中選擇一個項目,它就會自動調用。這就是我的例子中eventListeners的用處。至於何時使用'search_complex.selectedItem.label',我假設您會在需要的地方使用它來設置搜索條件。如果'updateList()'使用'currentUserbase'數組的內容執行搜索,則可以在'search()'中將'search_complex.selectedItem.label'添加到數組中。 – 2011-03-03 17:03:34
@jason,感謝您在這裏幫助我,但我仍然對事物感到困惑,我實際上使用AutoComplete高級示例中的autocomple框在以下鏈接中:http://developer.yahoo.com/flash/astra-flash/ autocomplete/examples.html現在,當我使用search_complex.addEventListener(Event.CHANGE,搜索);它只會自動執行搜索下拉列表中的第一項內容,而不是用戶選擇的項目。 updateList只是在搜索功能完成時用結果更新另一個列表。 – hanna 2011-03-03 17:23:14