16.3. Event Classes

You will need an event class for both the login and logout functionality.

Start with the login event by creating a new event class named LoginEvent in the com.FlexBlog.events package. Edit it to match the following:

package com.FlexBlog.events
{
    import com.FlexBlog.valueobjects.UserVO;
    import com.adobe.cairngorm.control.CairngormEvent;
    public class LoginEvent extends CairngormEvent
    {
        public static const LOGIN:String = "loginEvent";
        public var user:UserVO;
        public function LoginEvent(user:UserVO, bubbles:Boolean=false,
cancelable:Boolean=false)
        {
            super(LOGIN, bubbles, cancelable);
            this.user =user;
        }
    }
}

The LoginEvent takes in a UserVO that it will pass along to the LoginCommand. This UserVO will simply have the userName and password properties populated so that they can be used to locate the account in the delegate class.

Next, create the logout event by creating a new event class named LogoutEvent in the com.FlexBlog.events package. Edit it to match the following:

package com.FlexBlog.events
{
    import com.adobe.cairngorm.control.CairngormEvent;
    public class LogoutEvent extends CairngormEvent
    {
      public static const LOGOUT:String = 'logoutEvent';
      public function LogoutEvent(bubbles:Boolean=false, cancelable:Boolean=false)
      {
            super(LOGOUT, bubbles, cancelable);
        }
    }
}

This event does not need to transfer any data and is only being used to trigger the corresponding command class that will handle the login procedure.

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.