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

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.