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.4. Delegate Classes

Both the loading and the adding of comments require interaction with the database, so you will need delegate classes for both procedures.

Start with the delegate for loading comments. In the com.FlexBlog.delegates package create a new delegate class named LoadCommentsDelegate. Edit the class to match the following:

package com.FlexBlog.delegates
{
    import com.FlexBlog.valueobjects.PostVO;
    import flash.errors.SQLError;
    import mx.rpc.IResponder;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import sql.FlexBlogDatabaseManager;
    public class LoadCommentsDelegate
    {
        private var responder:IResponder;
        public function LoadCommentsDelegate(responder:IResponder)
        {
            this.responder = responder;
        }
        public function loadComments(post:PostVO):void{
            var dbManager:FlexBlogDatabaseManager =
FlexBlogDatabaseManager.getInstance();
            try{
                var comments:Array = dbManager.getComments(post);
                var event:ResultEvent = new
ResultEvent(ResultEvent.RESULT,false,true,{comments:comments})
                this.responder.result(event)
            }catch(error:SQLError){
                var faultEvent:FaultEvent = new FaultEvent(FaultEvent.FAULT);
                this.responder.fault(faultEvent);
            }
        }
    }
}

The loadComments function calls the getComments function of the FlexBlogDatabaseManager, which returns an array of CommentVO objects. This array is passed back to the command class in the comments property of the result object of the ResultEvent.

If something goes wrong while the comments are being retrieved, the fault function of the ...

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