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

19.5. Command Classes

You need command classes for both loading and adding comments.

Start with the command for loading comments. You need a property on the model to represent the comments loaded by the command class. Add the following to the FlexBlogModel:

public var comments:ArrayCollection =new ArrayCollection();

Now create the command class. In the com.FlexBlog.commands package create a new command class named LoadCommentsCommand. Edit the class to match the following:

package com.FlexBlog.commands
{
    import com.FlexBlog.delegates.LoadCommentsDelegate;
    import com.FlexBlog.events.LoadCommentsEvent;
    import com.FlexBlog.models.FlexBlogModel;
    import com.adobe.cairngorm.commands.ICommand;
    import com.adobe.cairngorm.control.CairngormEvent;
    import mx.rpc.IResponder;
    import mx.rpc.events.ResultEvent;
    public class LoadCommentsCommand implements ICommand, IResponder
    {
        private var model:FlexBlogModel = FlexBlogModel.getInstance();
        public function execute(event:CairngormEvent):void
        {
            var evt:LoadCommentsEvent = event as LoadCommentsEvent;
            var delegate:LoadCommentsDelegate = new LoadCommentsDelegate(this);
            delegate.loadComments(evt.post);
        }
        public function result(data:Object):void
        {
            var evt:ResultEvent = data as ResultEvent;
            this.model.comments.source = evt.result.comments;
        }
        public function fault(info:Object):void
        {
        }
    }
}

The execute function calls the loadComments function of the LoadCommentsDelegate, passing it the PostVO object from the LoadCommentsEvent event.

Using the comments property ...

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