Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle click event in Spark List control in Flex 4

I have a s:List component. I want to handle a click event to know what list item is selected. I don't see Click event in s:List. Any workarounds?

Thanks.

like image 205
motiver Avatar asked Feb 19 '10 21:02

motiver


2 Answers

I know I'm late to the party here, but the simplest way to get the selected node from list in a click event is to use the currentTarget property.

function myClickHandler(event:MouseEvent):void{
   Alert.show("My Var: " + event.currentTarget.selectedItem.myVar);
}

<s:List ... click="myClickHandler(event);">
...
</s:List>

see:

http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7cdb.html

like image 134
esBe Avatar answered Nov 18 '22 06:11

esBe


You can use the IndexChangeEvent.CHANGE on List http://docs.huihoo.com/flex/4/spark/events/IndexChangeEvent.html

Package spark.events Class public class IndexChangeEvent Inheritance IndexChangeEvent Event Object

Language Version: ActionScript 3.0 Product Version: Flex 4 Runtime Versions: Flash Player 10, AIR 1.5

The IndexChangeEvent class represents events that are dispatched when an index changes in a Spark component.

See also

spark.components.supportClasses.ListBase spark.components.List spark.components.ButtonBar

like image 4
Randy Avatar answered Nov 18 '22 06:11

Randy