User Guide

DataSet.addSort() 345
function modelChangedListener(evt_obj:Object):Void {
my_dg.enabled = (evt_obj.target.length > 0);
clear_button.enabled = my_dg.enabled;
}
function submitListener(evt_obj:Object):Void {
my_ds.addItem({firstName:firstName_ti.text, lastName:lastName_ti.text});
}
function addItemListener(evt_obj:Object):Void {
if ((evt_obj.item.firstName.length == 0) || (evt_obj.item.lastName.length
== 0)) {
Alert.show("Error, first name or last name cannot be blank.", "Error",
Alert.OK, _level0);
evt_obj.result = false;
} else {
firstName_ti.text = "";
lastName_ti.text = "";
}
}
function clearListener(evt_obj:Object):Void {
Alert.show("Are you sure you want to clear the data?", "Warning",
Alert.OK | Alert.CANCEL, _level0, clearConfirmListener);
}
function clearConfirmListener(evt_obj:Object):Void {
switch (evt_obj.detail) {
case Alert.OK:
my_ds.clear();
break;
case Alert.CANCEL:
break;
}
}
Select Control > Test Movie to test the document in the authoring environment. Enter some
text into both of the TextInput instances and then click the Submit button. A a new item
should be added to the DataGrid instance. Clicking the Clear button should display an Alert
component instance with a confirmation message asking if you want to clear the contents of
the DataGrid. Clicking OK clears the
dataProvider property of the DataSet component
(and then the dataProvider property of the DataGrid component, because of the binding).
Clicking Cancel dismisses the Alert component instance.
See also
DataSet.removeSort()