ActionScript 2.0 Components Language Reference |
|
|
|
| ComboBox component > ComboBox.addItemAt() | |||
Flash Player 6 (6.0.79.0).
Flash MX 2004.
comboBoxInstance.addItemAt(index,label[,data])comboBoxInstance.addItemAt(index, {label:label[,data:data]})comboBoxInstance.addItemAt(index,obj);
index A number 0 or greater that indicates the position at which to insert the item (the index of the new item).
label A string that indicates the label for the new item.
data The data for the item; it can be of any data type. This parameter is optional.
obj An object with label and data properties.
The index at which the item was added.
Method; adds a new item to the end of the list at the index specified by the index parameter. Indices greater than ComboBox.length are ignored.
Start with a ComboBox component instance named my_cb, and a Button component instance named my_btn. Add the following ActionScript to the Actions panel for the first frame of the main timeline. When you test the SWF file, click the combo box to see two items in it. Then click the button, and the next time you click the combo box, you'll see that it added another item labeled "first value":
my_cb.addItem({data:2, label:"second value"});
my_cb.addItem({data:3, label:"third value"});
var btnListener:Object = new Object();
btnListener.click = function() {
my_cb.addItemAt(0, {data:1, label:"first value"});
};
my_btn.addEventListener("click", btnListener);
|
|
|
|