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

Since both the retrieval of the categories and the add post process will need to interact with the database, you will need a delegate class for both these procedures.

Start with the category retrieval delegate. Create a new delegate class named LoadCategoriesDelegate in the com.FlexBlog.delegates package. Edit the class to match the following:

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

The LoadCategoriesDelegate simply calls the getCategories method on the FlexBlogDatabaseManager. This method returns an array of CategoryVO objects. This array is then assigned to the categories property of the ResultEvent result property and passed back to the command class.

If something goes wrong with the query, the fault function of the responder ...

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