RETRIEVE EVENT AND DATA FROM THE CAIRNGORMEVENT
DO PROCESSING, UPDATE MODEL
CALL EXTERNAL SERVICES USING A DELEGATE
CREATE SERVICE COMPONENT
CREATE SERVICE DELEGATE
CALL SERVICE DELEGATE
PROCESS RESULTS IN COMMAND
4.1) Every command class must have an execute method. This is passed the CairngormEvent that is mapped to the command in the AppController. The generic CairngormEvent needs to be recast as the specific type of event. For example:
public function execute( cgEvent : CairngormEvent ) : void
var messageEvent:DataChangeEvent = DataChangeEvent( cgEvent );
Any data packaged within the event may then be retrieved from the event (for example, form input data).
4.2) The execute method can change data held centrally in AppModelLocator. This might alter data that then, through bindings, updates components of the views. It might also change the current view.
4.3) The execute method might call a data service asynchronously. The data service would then communicate between the application and a remote service (for example through http).
4.3.1) Add a service component to the business.Services class. The service should have a unique id. For example:
<mx:HTTPService id="rssSourceService" url="http://del.icio.us/rss/RobOToole/web_development"/>
4.3.2) Create a delegate class to handle the request asynchronously, using this template (modify the class and method names appropriately). Esnure that it gets an instance of the service to be used for example:
this.service = ServiceLocator..getHTTPService(‘rssSourceService’)
4.3.3) When the service has loaded, it calls back to the result(rpcEvent:Object) method of the command. Ensure that this is present, and add to it code to process the event. Also ensure that there is a fault(rpcEvent:Object) method to handle service errors.
4.4.4) Now instantiate the delegate from the command class and start the async operation. For example:
var delegate : LoadEmployeesDelegate = new LoadEmployeesDelegate( this );