ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

Flex cairngorm overview and tutorial part2

Updated on March 27, 2011

This is a continuation for what I had explained here. If the flex application has to make calls to the external services, this can be done through the cairngorm service locator. A delegate class will be defined for each command class which would make such external http service calls. a sample code for the service locator and delegate is defined below.

<?xml version="1.0" encoding="utf-8"?>

<mx:HTTPService id="getAppService" url="" makeObjectsBindable="false" resultFormat="object" />


The service locator should also be included in the application.mxml file as below

<business:Services id="services" />

Creating the delegate class

When a command has to be a call to the external service. it is handled through a delegate class which would make the service call and forward the response to a IResponder. usually the the command class would only implement the IResponder interface also.

public class GetAppCommand implements ICommand, IResponder
 public function execute(event:CairngormEvent):void {
 	var delegate : AppInfoDelegate = new AppInfoDelegate( this );
public class AppInfoDelegate{
public function AppInfoDelegate( command : IResponder ) {			
	var qn : QName = new QName(ServiceLocator.getInstance().getHTTPService( 'getAppService' ).url, "app");
	// constructor will store a reference to the service 
	this.service = ServiceLocator.getInstance().getHTTPService( 'getAppService' );
	// and store a reference to the command 
	this.command = command;

    public function getAppConfigurationService() : void {
      var token:AsyncToken = service.send();
	// notify this command when the service call completes
      token.addResponder( command );

The delegate has added the responder to the token received from the service call. It would call the result() method defined in the IResponder. The responder would handle the response and then dispatch another cairngorm event which would be handled by another command.


    0 of 8192 characters used
    Post Comment

    No comments yet.