views:

2021

answers:

2

I have a regular control in my code with serveral items.

<mx:List id="myList">
 <mx:String>Item 1</mx:String>
 <mx:String>Item 2</mx:String>
</mx:List>

I have some other code which runs and populates the list. How do I select the first item in the newly populated list using code?

+7  A: 

That would be myList.selectedItem, if you have a reference to the object you would like to select, or myList.selectedIndex, if you have an index into the data source. Both properties are inherited from the ListBase class. They're documented in the ActionScript 3.0 Language Reference.

Simon
A: 

Try using the getItemAt method of the List's dataProvider like this... myList.dataProvider.getItemAt(0).