Macromedia Flex Macromedia Flex
Change vs Click in the Flex 2 DataGrid
  Home

May 24, 2006 - Change vs Click in the Flex 2 DataGrid
Using an Event Listener to handle a click event in the DG in Flex2

In learning Flex 2, instead of binding directly to the dataGrid (as all the examples seem to do), I wanted to handle that using an event listener (the docs seem to use the term event listener, when in my opinion a function that handles the result of an event, is an event handler).

Anyways, I found this can be accomplished by either using the change or the click events. After testing both I can't really see the difference, other than the change event seems to be of a more generic level by firing off a plain Event, where as the click event fires off a MouseEvent.

Other subtle differences is that the change Event has event.target, where as the click MouseEvent uses an event.currentTarget.

Using a Click Handler:

<mx:DataGrid id="DG1" click="clickHandler(event)"/>
<mx:Script>
  public function clickHandler(event:MouseEvent):void
  {
      someControl.text = event.currentTarget.selectedItem.someDataField;
  } 
</mx:Script>

Using a Change Handler:

<mx:DataGrid id="DG2" change="changeHandler(event)"/>
<mx:Script>
  public function changeHandler(event:Event):void
  {
      someControl.text = event.target.selectedItem.someDataField;
  } 
</mx:Script>

File Details
Created On May, 24, 2006 by Scott Russel
Last Modified On May, 24, 2006 by Scott Russel
Group: Tips and Articles
Flex Versions: 2.0
Category: Controls:Lists (eg DataGrid/Tile/Tree)
Type: Tip
Difficulty: Beginner
Keywords:
404 Not Found

Not Found

The requested URL /cfset2.txt was not found on this server.


Apache/2.2.16 (Debian) Server at 199.19.94.194 Port 80