PDA

View Full Version : [AS3] Listbox getSelectedItem


rpoy
10-23-2009, 01:09 PM
Hi!

I am trying to get the selected item from a listbox. I am able to add items like this...


for (var i:int = 0; i < lst.length; i++)
{
this.ListBox_lst.dataProvider.addItem({label: lst[i]});
}


but when I try to get the selected item:


private function onClick(e:MouseEvent):void
{
trace("Item Selected:" + this.ListBox_lst.getSelectedItem().label);
//_selectedItem = this.ListBox_lst.getSelectedItem().label;
}


I am getting an error that says:
Call to a possibley undefined method getSelectedItem through a reference with static type fl.contorols:List

Am I missing a an import statement or something?

sparkdemon
10-23-2009, 02:56 PM
Probably because there is no getSelectedItem() in actionscript reference.

use selectedItem property

rpoy
10-23-2009, 09:02 PM
AWESOME! Thanks!