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.5. Command Classes

The login and logout procedures each need a command class.

Start with the login command by creating a new command class named LoginCommand in the com.FlexBlog.commands package. Edit it to match the following:

package com.FlexBlog.commands { import com.FlexBlog.delegates.LoginDelegate; import com.FlexBlog.events.LoginEvent; import com.FlexBlog.models.FlexBlogModel; import com.FlexBlog.valueobjects.UserNotificationVO; import com.adobe.cairngorm.commands.ICommand; import com.adobe.cairngorm.control.CairngormEvent; import mx.rpc.IResponder; import mx.rpc.events.ResultEvent; public class LoginCommand implements ICommand, IResponder { private var model:FlexBlogModel = FlexBlogModel.getInstance(); public function execute(event:CairngormEvent):void { var evt:LoginEvent = event as LoginEvent; var delegate:LoginDelegate = new LoginDelegate(this); delegate.login(evt.user); } public function result(data:Object):void { var evt:ResultEvent = data as ResultEvent; var notification:UserNotificationVO = new UserNotificationVO(); if(evt.result.user){ this.model.currentUser = evt.result.user; }else{ notification.type = UserNotificationVO.ERROR_MESSAGE; notification.message = 'No account with that user name and password could be found'; this.model.userNotification =notification; } } public function fault(info:Object):void { var notification:UserNotificationVO = new UserNotificationVO(); notification.type = UserNotificationVO.ERROR_MESSAGE; notification.message = 'A server error ...

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