package command; import openfl.Vector; import vo.Rider; import feathers.data.ArrayCollection; import openfl.Lib; import haxe.DynamicAccess; import business.LoadRidersDelegate; import com.adobe.cairngorm.commands.ICommand; import com.adobe.cairngorm.control.CairngormEvent; import feathers.rpc.IResponder; import feathers.rpc.events.ResultEvent; import haxe.Json; import model.AppModelLocator; class LoadRidersCommand implements ICommand implements IResponder { private var model = AppModelLocator.getInstance(); public function execute(cgEvent:CairngormEvent):Void { // create a worker who will go get some data and pass it a reference to this command so the delegate knows where to return the data var delegate = new LoadRidersDelegate(this); // make the delegate do some work delegate.loadRidersService(); trace(this + "execute()"); } // this is called when the delegate receives a result from the service public function result(rpcEvent:Dynamic):Void { // populate the riders DP in the model locator with the JSON results from the service call var riders:Array = cast(rpcEvent, ResultEvent).result; model.ridersListDP = new ArrayCollection(riders); trace("ridersListDP.length --> " + model.ridersListDP.length); /*var data:DynamicAccess = Json.parse(cast(rpcEvent, ResultEvent).result); */ /*var data:DynamicAccess = Json.parse(e.target.data); for (key => value in data){ ConfigValues.data[key] = value; } */ } // this is called when the delegate receives a fault from the service public function fault(rpcEvent:Dynamic):Void { // store an error message in the model locator // labels, alerts, etc can bind to this to notify the user of errors model.errorStatus = "Fault occured in LoadEmployeesCommand."; } }