O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

17.5. Command Classes

You need a command class for the loading of the categories and for adding a post. Start with the command class for loading the categories.

You will need to store the categories that are loaded in a property on the ModelLocator. Add the following to the FlexBlogModel:

public var categories:ArrayCollection = new ArrayCollection();

Make sure that Flex has added the import for the ArrayCollection class.

Next, in the com.FlexBlog.commands package create a new command class called LoadCategoriesCommand. Edit the class to match the following:

package com.FlexBlog.commands
{
    import com.FlexBlog.delegates.LoadCategoriesDelegate;
    import com.FlexBlog.models.FlexBlogModel;
    import com.FlexBlog.valueobjects.UserNotificationVO;
    import com.adobe.cairngorm.commands.ICommand;
    import com.adobe.cairngorm.control.CairngormEvent;
import mx.rpc.IResponder;
    import mx.rpc.events.ResultEvent;
    public class LoadCategoriesCommand implements ICommand, IResponder
    {
        private var model:FlexBlogModel = FlexBlogModel.getInstance();
        public function execute(event:CairngormEvent):void
        {
            var delegate:LoadCategoriesDelegate = new LoadCategoriesDelegate(this);
            delegate.loadCategories()
        }
        public function result(data:Object):void
        {
            var evt:ResultEvent = data as ResultEvent;
            var notification:UserNotificationVO = new UserNotificationVO();
            if (evt.result.categories){
                this.model.categories.source = evt.result.categories;
            }
        }
        public function fault(info:Object):void
        {
        }
    }
}

The execute function simply calls ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required