0

我正在尝试创建一个组合框,该组合框将填充可能的自动完成结果,我首先将所有单词放在一个与用户输入进行比较的数组中,然后将其放入将单词添加到组合框的 switch 语句中。但是,当输入更改时,我无法正确地从组合框中删除结果。

var dictionary:Vector.<String> = new Vector.<String>();
dictionary.push("University Chapel");
dictionary.push("IT Building");
dictionary.push("Student Centre");
dictionary.push("EMS Building");
dictionary.push("EMB Building");
dictionary.push("Monastry Hall");
dictionary.push("Conference Centre");
dictionary.push("Client Service Centre");
var objects:Vector.<MovieClip> = new Vector.<MovieClip>();
stage.focus = inputBox;
inputBox.addEventListener(Event.CHANGE, onCompletions);
function onCompletions(event:Event):void{
for(var i:int = 0; i < dictionary.length; ++i){
    if(dictionary[i].indexOf(inputBox.text) >= 0){
        switch(dictionary[i])   {
            case 'IT Building':
                cbox.addItemAt({label:"IT Building", data:"screenData" + newRow},0);  
                break;
            case 'University Chapel':
                cbox.addItemAt({label:"University Chapel", data:"screenData" + newRow},0);
                break;

            case 'Student Centre':
                cbox.addItemAt({label:"Student Centre", data:"screenData" + newRow},0);
                break;

            case 'EMS Building':
                cbox.addItemAt({label:"EMS Building", data:"screenData" + newRow},0);
                break;

            case 'EMB Building':
                cbox.addItemAt({label:"EMB Building", data:"screenData" + newRow},0);
                break;

            case 'Monastry Hall':
                cbox.addItemAt({label:"Monastry Hall", data:"screenData" + newRow},0);
                break;

            case 'Conference Centre':
                cbox.addItemAt({label:"Conference Centre", data:"screenData" + newRow},0);
                break;

            case 'Client Service Centre':
                cbox.addItemAt({label:"Client Service Centre", data:"screenData" + newRow},0);
                break;
        }
    }
    else    {
        //cbox.removeAll(); //Where I attempted to remove all the results
    }
}

}

所以我试图从组合框中删除结果并重新评估它们,然后再次插入。就像一个附带问题一样,有没有办法通过 actionscript 扩展组合框?

提前致谢

4

1 回答 1

0

如果有人感兴趣,我可以让它工作,所以这基本上会创建一个自动完成搜索输入框。

var dictionary:Vector.<String> = new Vector.<String>();
dictionary.push("University Chapel");
dictionary.push("IT Building");
dictionary.push("Student Centre");
dictionary.push("EMS Building");
dictionary.push("EMB Building");
dictionary.push("Monastry Hall");
dictionary.push("Conference Centre");
dictionary.push("Client Service Centre");

stage.focus = inputBox;

inputBox.addEventListener(Event.CHANGE, onCompletions);
cbox.open();
function onCompletions(event:Event):void{
cbox.removeAll();
cbox.close();
for(var i:int = 0; i < dictionary.length; ++i){
    if(dictionary[i].indexOf(inputBox.text) >= 0 && inputBox.text != ''){
        switch(dictionary[i])   {
            case 'IT Building':
                cbox.addItemAt({label:"IT Building", data:"screenData"},0); 
                cbox.open();
                break;
            case 'University Chapel':
                cbox.addItemAt({label:"University Chapel", data:"screenData"},0);
                cbox.open();
                break;

            case 'Student Centre':
                cbox.addItemAt({label:"Student Centre", data:"screenData"},0);
                cbox.open();
                break;

            case 'EMS Building':
                cbox.addItemAt({label:"EMS Building", data:"screenData"},0);
                cbox.open();
                break;

            case 'EMB Building':
                cbox.addItemAt({label:"EMB Building", data:"screenData"},0);
                cbox.open();
                break;

            case 'Monastry Hall':
                cbox.addItemAt({label:"Monastry Hall", data:"screenData"},0);
                cbox.open();
                break;

            case 'Conference Centre':
                cbox.addItemAt({label:"Conference Centre", data:"screenData"},0);
                cbox.open();
                break;

            case 'Client Service Centre':
                cbox.addItemAt({label:"Client Service Centre", data:"screenData"},0);
                cbox.open();
                break;
        }
    }
}

}

于 2013-05-22T17:20:50.700 回答