Using binding to capture the selection of a List-based component
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.ArrayCollection;
import mx.events.ListEvent;
import mx.controls.Alert;
public var myAC:ArrayCollection = new ArrayCollection([
{name:"A", email:"a@d.com"},
{name:"B", email:"b@d.com"}]);
public function handleClick(evt:ListEvent):void
{
Alert.show(evt.rowIndex + " / col:" + evt.columnIndex + "." + "for " + evt.currentTarget.selectedItem.name);
}
</mx:Script>
<mx:DataGrid id="dg" width="500" height="150"
dataProvider="{myAC}">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Contact Name" width="300" />
<mx:DataGridColumn dataField="email" headerText="E-Mail" width="200" />
</mx:columns>
</mx:DataGrid>
<mx:Label text="selected: {dg.selectedItem.name} ({dg.selectedItem.email})" fontSize="16" />
</mx:Application>
Related examples in the same category