User Guide
DataGrid.change 279
Usage
listenerObject = new Object();
listenerObject.change = function(eventObject){
// Insert your code here.
}
myDataGridInstance.addEventListener("change", listenerObject)
Description
Event; broadcast to all registered listeners when an item has been selected.
Version 2 components use a dispatcher/listener event model. When a DataGrid component
dispatches a
change event, the event is handled by a function (also called a handler) that is
attached to a listener object (
listenerObject) that you create. You call the
addEventListener() method and pass it the name of the handler as a parameter.
When the event is triggered, it automatically passes an event object (
eventObject) to the
handler. Each event object has properties that contain information about the event. You can
use these properties to write code that handles the event. The
DataGrid.change event’s event
object has one additional property,
type, whose value is "change". For more information, see
“EventDispatcher class” on page 499.
Example
In the following example, a handler called dgListener is defined and passed to
grid.addEventListener() as the second parameter. The event object is captured by the
change handler in the evt_obj parameter. When the change event is broadcast, a trace
statement is sent to the Output panel. With a DataGrid instance named
my_dg on the Stage,
paste the following code in the first frame of the main timeline:
// Set up sample data.
my_dg.dataProvider = [{name:"Clark", score:3135}, {name:"Bruce",
score:403}, {name:"Peter", score:25}];
// Create listener object.
var dgListener:Object = new Object();
dgListener.change = function(evt_obj:Object) {
trace("The selection has changed to " + evt_obj.target.selectedIndex);
};
// Add listener.
my_dg.addEventListener("change", dgListener);