User Guide

802 List component
Example
The following example selects the first item in a list by default and displays the index of the
currently selected whenever the user selects a new item:
var my_list:mx.controls.List;
my_list.addItem({data:"flash", label:"Flash"});
my_list.addItem({data:"dreamweaver", label:"Dreamweaver"});
my_list.addItem({data:"coldfusion", label:"ColdFusion"});
// Select first item by default.
my_list.selectedIndex = 0;
var listListener:Object = new Object();
listListener.change = function(evt_obj:Object) {
trace("selectedIndex = " + evt_obj.target.selectedIndex);
}
my_list.addEventListener("change", listListener);
See also
List.selectedIndices, List.selectedItem, List.selectedItems
List.selectedIndices
Availability
Flash Player 6 (6.0.79.0).
Edition
Flash MX 2004.
Usage
listInstance.selectedIndices
Description
Property; an array of indices of the selected items. Assigning this property replaces the current
selection. Setting
selectedIndices to a zero-length array (or undefined) clears the current
selection. The value is
undefined if nothing is selected.
The
selectedIndices property reflects the order in which the items were selected. If you
click the second item, then the third item, and then the first item,
selectedIndices returns
[1,2,0].