7.4. How Do You Use Them?

Command classes decide how Cairngorm events are handled. Before a command will do anything, it must be registered in the FrontController with a corresponding event. You do this using the addCommand function of the FrontController, as in the following:

addCommand(ExampleEvent.EXAMPLE_TYPE, ExampleCommand);

In most cases your command classes will be updating the model, often in response to some call to the server. An example of this can be seen in the GetProductsCommand from the Cairngorm web store:

package com.adobe.cairngorm.samples.store.command { import mx.rpc.IResponder; import com.adobe.cairngorm.commands.ICommand; import com.adobe.cairngorm.control.CairngormEvent; import com.adobe.cairngorm.samples.store.business.ProductDelegate; import com.adobe.cairngorm.samples.store.model.ShopModelLocator; import com.adobe.cairngorm.samples.store.util.Comparator; import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.controls.Alert; import mx.collections.ICollectionView; import mx.collections.Sort; import mx.collections.SortField; import mx.utils.ArrayUtil; public class GetProductsCommand implements ICommand, IResponder { public function GetProductsCommand(){} public function execute( event : CairngormEvent ): void { if( ShopModelLocator.getInstance().products == null ) { var delegate : ProductDelegate = new ProductDelegate( this ); delegate.getProducts(); } else { Alert.show( "Products already retrieved!" ); return; } } public function ...

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.