box-o-sand/03a2b-crud-dynamic/CustomApp.as

56 lines
1.8 KiB
ActionScript
Raw Normal View History

package
{
import mx.core.Application;
import mx.rpc.events.ResultEvent;
import mx.collections.XMLListCollection;
public class CustomApp extends Application
{
public var params:Object = new Object();
[Bindable]
public var listData:XMLListCollection;
function CustomApp()
}
{
public function resultHandler(event:ResultEvent):void {
var result:XML = XML(event.result);
var xmlList:XMLList = result.data.children();
listData = new XMLListCollection(xmlList);
}
public function insertItemHandler(event:ResultEvent):void {
fill();
}
public function fill():void{
employeesService.removeEventListener(ResultEvent.RESULT,insertItemHandler);
employeesService.addEventListener(ResultEvent.RESULT,resultHandler);
employeesService.method = "GET";
params['method'] = "FindAllEmployees";
employeesService.cancel();
employeesService.send(params);
viewstack1.selectedIndex=1;
}
public function insertEmployee():void{
employeesService.removeEventListener(ResultEvent.RESULT,resultHandler);
employeesService.addEventListener(ResultEvent.RESULT,insertItemHandler);
employeesService.method = "POST";
params = {"method": "InsertEmployee", "id": NaN, "firstName": inputFirst.text,
"lastName": inputLast.text, "officePhone": inputPhone.text};
employeesService.cancel();
employeesService.send(params);
clearInputFields();
}
public function clearInputFields():void{
inputFirst.text = "";
inputLast.text = "";
inputPhone.text = "";
}
}
}