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

15.3. Event Classes

To get to the registration view you need some method of changing the main view. You could simply have the buttons in the main view change the selected index of the main ViewStack — that would solve the immediate problem, but what if a component nested deeper in the application wants to change the main view?

For example, the cancel button on the registration form is supposed to return the user to the posts view. Such a nested component would have to either have a reference to the ViewStack or dispatch some event that the main ViewStack would have to listen for. The latter is a possible solution, but since you are using Cairngorm anyway, let's examine how Cairngorm can solve this issue.

You can bind the selectedIndex of the ViewStack to a property on the ModelLocator and then have your sub-views dispatch an event that is responsible for changing the main view by updating the variable on the ModelLocator.

In the com.FlexBlog.events package create a new event named ChangeMainViewEvent and edit it to match the following:

package com.FlexBlog.events
{
    import com.adobe.cairngorm.control.CairngormEvent;

    public class ChangeMainViewEvent extends CairngormEvent
    {
        public static const CHANGE_MAIN_VIEW:String = 'changeMainView';
        public static const POSTS_VIEW:int = 0;
        public static const WRITE_VIEW:int = 1;
        public static const REGISTER_VIEW:int = 2;
        public var goTo:int;
        public function ChangeMainViewEvent(goTo:int, bubbles:Boolean=false,
cancelable:Boolean=false) { super(CHANGE_MAIN_VIEW, ...

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