PDA

View Full Version : handling itemClick events in actionscript


sbeausol
02-16-2009, 08:16 PM
Hi everyone-

I'm slowly plugging away on a project, and one thing I am hoping to implement is an event off of a click on a cell in my datagrids. My understanding is that i can do this like this:
<mx:DataGrid id="myGrid" width="350" height="150"
itemClick="itemClickEvent(event);">


Where a function itemClickEvent will handle the event. All of my datagrids, however are dynamically generated in actionscript and I can't seem to figure out how to set the itemClick parameter for my datagrid using actionscript.
My datagrid looks like this:

var vBox:VBox = new VBox();
var dataGrid:DataGrid = new DataGrid();
var column1:DataGridColumn = new DataGridColumn();
var column2:DataGridColumn = new DataGridColumn();
column1.dataField = "aa";
column1.headerText = "Seq";
column1.width = 35;
column2.dataField = "Nnum";
column2.width = 25;
column2.headerText = "#";
dataGrid.columns = new Array(column1, column2, custColumn1, custColumn2);
dataGrid.dataProvider = array;
dataGrid.sortableColumns = false;
dataGrid.percentHeight = 100;
vBox.addChild(dataGrid);

iamaflexdeveloper
02-18-2009, 03:32 PM
u can do like this

datagrid.addEventListener(ListEvent.ITEM_CLICK,onI temClick);

function onItemClick(event:ListEvent):void
{
/* event handling code here*/
}

sbeausol
02-19-2009, 01:44 AM
that did it, thanks!