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

16.4. Delegate Classes

You need a delegate class for login functionality. However, since logout requires only that the data for the current user be destroyed, you do not really need to retrieve or update any data from the database and no delegate class is required.

Create a new delegate class named LoginDelegate in the com.FlexBlog.delegates package. 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 LoginDelegate
    {
        private var responder:IResponder;
        public function LoginDelegate (responder:IResponder)
        {
            this.responder = responder;
        }
        public function login(user:UserVO):void{
            var dbManager:FlexBlogDatabaseManager =
FlexBlogDatabaseManager.getInstance();
            try{
            var isUser:UserVO =  dbManager.login(user);
            var event:ResultEvent = new
ResultEvent(ResultEvent.RESULT,false,true,{user:isUser})
            this.responder.result(event)
            }catch(error:SQLError){
                var faultEvent:FaultEvent = new FaultEvent(FaultEvent.FAULT);
                this.responder.fault(faultEvent);
            }
        }
    }
}

The LoginDelegate login function takes in a UserVO and passes it to the login function on the FlexBlogDatabaseManager class to simulate the service call. If an account is found, the login method of the FlexBlogDatabaseManager class returns a UserVO object with the account information for that user. If no account is found, 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