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 =
                var comments:Array = dbManager.getComments(post);
                var event:ResultEvent = new
                var faultEvent:FaultEvent = new FaultEvent(FaultEvent.FAULT);

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

Get Professional Cairngorm™ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.