5.4. How Do You Use It?

In order for the FrontController class to be able to capture dispatched Cairngorm events, there needs to be an instance of it in the application, normally in the main application file.

To include the FrontController class you created, create a namespace in the main application tag pointing to the location where you created the class. Then simply add an instance of it to the main application, as in the following:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlsn:business="com.cairngormexample.business.*">
  <business:CairngormExampleController id="controller"/>
</mx:Application>

Once you have this instance in the application, you then need to register your event-command pairings in the FrontController class that you created. You do this by using the addCommand function, as can be seen in the ShopController class from the Cairngorm store application:

package com.adobe.cairngorm.samples.store.control { import com.adobe.cairngorm.control.FrontController; import com.adobe.cairngorm.samples.store.command.* import com.adobe.cairngorm.samples.store.event.UpdateShoppingCartEvent; import com.adobe.cairngorm.samples.store.event.FilterProductsEvent; import com.adobe.cairngorm.samples.store.event.GetProductsEvent;; import com.adobe.cairngorm.samples.store.event.SortProductsEvent; import com.adobe.cairngorm.samples.store.event.ValidateOrderEvent; import com.adobe.cairngorm.samples.store.event.ValidateCreditCardEvent; ...

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.