User Guide
ComboBox.addItem() 171
ComboBox.addItem()
Availability
Flash Player 6 (6.0.79.0).
Edition
Flash MX 2004.
Usage
comboBoxInstance.addItem(label[, data])
comboBoxInstance.addItem({label:label[, data:data]})
comboBoxInstance.addItem(obj);
Parameters
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 a label property and an optional data property.
Returns
The index at which the item was added.
Description
Method; adds a new item to the end of the list.
Example
With a ComboBox component instance named my_cb, add the following ActionScript to the
Actions panel for the first frame of the main timeline. This ActionScript creates a ComboBox
with three items; each has a data value and a label string. When you test the SWF file, and
click one of the items, the Output panel displays the identity of the “target” the data value and
the label:
// Add Items to Combo Box.
my_cb.addItem("this is an Item");
my_cb.addItem({data:2, label:"second value"});
my_cb.addItem({data:3, label:"third value"});
// Add event listener and event handler function.
var cbListener:Object = new Object();
cbListener.change = function(evt_obj:Object):Void {
var currentlySelected:Object = evt_obj.target.selectedItem;
trace(evt_obj.target);
trace("data: "+currentlySelected.data);
trace("label: "+currentlySelected.label);
};
my_cb.addEventListener("change", cbListener);