修改数组不会“通知”您需要重新分配 dataProvider 的更改列表。
var barColours:Array = new Array();
barColours = ["red", "green", "blue", "orange", "purple"];
comboBox.dataProvider = new DataProvider(barColours);
comboBox.addEventListener(Event.CHANGE, onChange);
comboBox.x = 670;
comboBox.y = 55;
minus_btn.addEventListener(MouseEvent.CLICK, takeAwayCol);
function takeAwayCol(ev:MouseEvent):void
{
barColours.pop();
comboBox.dataProvider = new DataProvider(barColours);
}
根据评论编辑
var barColours:Array = ["red", "green", "blue", "orange", "purple"];
var removedBarColours:Array = new Array();
comboBox.dataProvider = new DataProvider(barColours);
comboBox.addEventListener(Event.CHANGE, onChange);
comboBox.x = 670;
comboBox.y = 55;
minus_btn.addEventListener(MouseEvent.CLICK, takeAwayCol);
function takeAwayCol(ev:MouseEvent):void
{
//if you need to pull from the beginning of the list instead of the end use shift/unshift method(s) of Array
removedBarColours.push(barColours.pop());
comboBox.dataProvider = new DataProvider(barColours);
}
function addCol(ev:MouseEvent):void
{
barColours.push(removedBarColours.pop());
comboBox.dataProvider = new DataProvider(barColours);
}