Skip to Main Content
Professional Cairngorm™
book

Professional Cairngorm™

by Jeremy Wischusen
November 2009
Intermediate to advanced content levelIntermediate to advanced
357 pages
8h 20m
English
Wrox
Content preview from Professional Cairngorm™

15.5. Command Classes

Since you will be changing main views by binding to a variable on the ModelLocator, you need to add that variable to the model. Add the following to the FlexBlogModel:

public var mainView:int;

Now you need a command class to update this variable. In the com.FlexBlog.commands package create a new command class named ChangeMainViewCommand and edit to match the following:

package com.FlexBlog.commands
{
    import com.FlexBlog.events.ChangeMainViewEvent;
    import com.FlexBlog.models.FlexBlogModel;
    import com.adobe.cairngorm.commands.ICommand;
    import com.adobe.cairngorm.control.CairngormEvent;
    public class ChangeMainViewCommand implements ICommand
    {
        private var model:FlexBlogModel = FlexBlogModel.getInstance();
        public function execute(event:CairngormEvent):void
        {
            var evt:ChangeMainViewEvent = event as ChangeMainViewEvent;
            this.model.mainView = evt.goTo;
        }
    }
}

This command updates the mainView property of the ModelLocator.

To return for a moment to the idea of dealing with change (e.g., changing the main view to be something other than a ViewStack), you do not even have to touch the command class, as all it does is update the model with the value passed in the goTo property of the event. As long as you have updated the event and the model to expect the same type of parameter, you are good to go.

Now register the ChangeMainViewEvent and ChangeMainViewCommand in the FlexBlogController:

public function FlexBlogController() { super(); addCommand(ChangeMainViewEvent.CHANGE_MAIN_VIEW, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional Java® JDK®, 6th Edition

Professional Java® JDK®, 6th Edition

W. Clay Richardson, Jeff Scanlon, Donald Avondolio, Mark W. Mitchell, Scot Schrager

Publisher Resources

ISBN: 9780470497265Purchase book