height="600">
import mx.events.*;
import mx.collections.*;
public function collectionEventHandler(event:CollectionEvent):void {
switch(event.kind) {
case CollectionEventKind.ADD:
addLog("Item "+ event.location + " added");
break;
case CollectionEventKind.REMOVE:
addLog("Item "+ event.location + " removed");
break;
case CollectionEventKind.REPLACE:
addLog("Item "+ event.location + " Replaced");
break;
case CollectionEventKind.UPDATE:
addLog("Item updated");
break;
}
}
public function addLog(str:String):void {
log.text += str + "\n";
}
public function addPerson():void {
ac.addItem({first:firstInput.text, last:lastInput.text,email:emailInput.text});
}
public function removePerson():void {
if (dg.selectedIndex >= 0) {
ac.removeItemAt(dg.selectedIndex);
}
}
public function updatePerson():void {
if (dg.selectedItem !== null) {
ac.setItemAt({first:firstInput.text, last:lastInput.text,email:emailInput.text}, dg.selectedIndex);
}
}
public function dgChangeHandler():void {
firstInput.text = dg.selectedItem.first;
lastInput.text = dg.selectedItem.last;
emailInput.text = dg.selectedItem.email;
}