我正在尝试创建一个组合框,该组合框将填充可能的自动完成结果,我首先将所有单词放在一个与用户输入进行比较的数组中,然后将其放入将单词添加到组合框的 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 扩展组合框?
提前致谢