PDA

View Full Version : select first item in listBox through actioncript


mgrubervs
11-02-2006, 02:45 AM
Is there a way to select the first item in a listBox component and have the change handler fire when it is first loaded?

Any direction would certainly be appreciated.

:confused:

Mazoonist
11-02-2006, 03:07 AM
var myArray:Array = new Array("Bill", "Sam", "Laura", "Phillip", "Sandra")
myList.dataProvider = myArray;
myList.selectedIndex = 0;
toDo();
myList.changeHandler = toDo;

function toDo() {
trace("you chose " + myList.selectedItem);
}
Just drag out a List component, name it myList, and put the above code in frame 1. The third line automatically selects the first item in the list.

To make a handler that can be executed once right away, make it a separate function with a name that you can call. That way you can call it with code and you can also set the list box's changeHandler to be equal to it. Hope that helps.