Skip to Main Content
Professional Cairngorm™
book

Professional Cairngorm™

by Jeremy Wischusen
November 2009
Intermediate to advanced content levelIntermediate to advanced
357 pages
8h 20m
English
Wrox
Content preview from Professional Cairngorm™

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional Java® JDK®, 6th Edition

Professional Java® JDK®, 6th Edition

W. Clay Richardson, Jeff Scanlon, Donald Avondolio, Mark W. Mitchell, Scot Schrager

Publisher Resources

ISBN: 9780470497265Purchase book