ActionScript 2.0 Components Language Reference |
|
|
|
| List component > List.selectedIndex | |||
Flash Player 6 (6.0.79.0).
Flash MX 2004.
listInstance.selectedIndex
Property; the selected index of a single-selection list. The value is undefined if nothing is selected; the value is equal to the last item selected if there are multiple selections. If you assign a value to selectedIndex, any current selection is cleared and the indicated item is selected.
Using the selectedIndex property to change selection doesn't dispatch a change event. To dispatch the change event, use the following code:
my_list.dispatchEvent({type:"change", target:my_list});
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);
List.selectedIndices, List.selectedItem, List.selectedItems
|
|
|
|