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

15.4. Delegate Classes

Now that you have the event and command classes created, you are going to create a delegate to access the service.

In the com.FlexBlog.delegates package create a class named RegisterUserDelegate and edit it to match the following:

package com.FlexBlog.delegates
{
    import com.FlexBlog.valueobjects.UserVO;
    import flash.errors.SQLError;
    import mx.rpc.IResponder;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import sql.FlexBlogDatabaseManager;
    public class RegisterUserDelegate
    {
        private var responder:IResponder;
        public function RegisterUserDelegate(responder:IResponder)
        {
            this.responder = responder;
        }
        public function register(user:UserVO):void{
            var dbManager:FlexBlogDatabaseManager =
FlexBlogDatabaseManager.getInstance();
            try{
            var userAdded:int =  dbManager.registerUser(user);
            var event:ResultEvent = new
ResultEvent(ResultEvent.RESULT,false,true,{added:userAdded})
            this.responder.result(event)
            }catch(error:SQLError){
                var faultEvent:FaultEvent = new FaultEvent(FaultEvent.FAULT);
                this.responder.fault(faultEvent);
            }
        }
    }
}

Here we are seeing the first occurrence of interaction with the backend using the SQL utility classes. The register method takes in a UserVO as a parameter and passes it to the registerUser method of the FlexBlogDatabaseManager.

The registerUser method returns an integer indicating the success or failure of the add user operation. If an account with the supplied user name and password exists, you will get back a value of −1; ...

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