I've done what Bjorn recommends for a project and have a follow-up
$0.02 or question. I created an event type NavigateURL which I
broadcast from the event handlers for my buttons in the views. The
command for this event type then updates my modelLocator property
(app_State).
Question is...Is this a case of "loose coupling overkill" or a
worthwhile process???
The Command code:
package com.post.commands
{
import com.adobe.cairngorm.business.Responder;
import com.adobe.cairngorm.commands.Command;
import com.adobe.cairngorm.control.CairngormEvent;
import com.post.model.ModelLocator;
public class NavigateCommand implements Command, Responder {
public function execute(p_event:CairngormEvent):void {
trace("NavigateCommand::execute function, p_event.type: " + p_event.type);
switch(p_event.type) {
//Redirect the user to the Intro view - Intro.mxml
case NavigateEvent.NAVIGATE_INTRO:
ModelLocator.getInstance().app_state = ModelLocator.STATE_INTRO;
break;
//Redirect the user to the Register view - Register.mxml
case
NavigateEvent.NAVIGATE_REGISTER:
ModelLocator.getInstance().app_state = ModelLocator.STATE_REGISTRATION;
break;
//Redirect the user to the Login view - Login.mxml
case NavigateEvent.NAVIGATE_LOGIN:
ModelLocator.getInstance().app_state = ModelLocator.STATE_LOGIN;
break;
}
}
And the event itself:
package com.post.events {
import com.adobe.cairngorm.control.CairngormEvent;
public class NavigateEvent extends CairngormEvent {
public static var NAVIGATE_INTRO:String = "navigateIntro";
public static var NAVIGATE_LOGIN:String = "navigateLogin";
public static var NAVIGATE_REGISTER:String = "navigateRegister";
public var strUser:String;
public var strPass:String;
public function NavigateEvent(p_NavType:String) {
//Constructor function which receives the Navigation Type
//from the view calling the event via the controller.
//Results in a separate function in the NavigateCommand executing.
super(p_NavType, false, true);
}
}
}
Add the events / command association in the controller:
addCommand(NavigateEvent.NAVIGATE_REGISTER, NavigateCommand);
addCommand(NavigateEvent.NAVIGATE_LOGIN, NavigateCommand);
addCommand(NavigateEvent.NAVIGATE_INTRO, NavigateCommand);
--- In [email protected], "bjorn.schultheiss"
<[EMAIL PROTECTED]> wrote:
>
> Hi Michelle,
>
> Have a go at using the viewStack container.
> create a property:Number in your modelLocator and bind the
> selectedIndex property of your viewstack to the property on your model
> Locator.
> for example
>
> <mx:ViewStack
> selectedIndex="{ModelLocator.getInstance().currentViewIndex}" >
>
> check out some of the examples on Alex Ulhmanns blog or try
> cairngormdocs.org :)
>
> Bjorn
>
> --- In [email protected], "Michelle Grigg" <michellejg@>
> wrote:
> >
> > Greetings,
> >
> > I am having a bit of a problem working out exactly how to navigate
> > through my application which will be using the Cairngorm 2
> architecture.
> >
> > It currently has the following views: a Login page, a Task List, a
> > Task and a Finish page. The task list can have any where up to 8
> > tasks displayed so the user will be switching between Task List and
> > Task quite often.
> >
> > The flow between these views will be accessed through button events
> > (ie, login button, or a start button to start the task etc). There
> > will be only one View shown to the user at any one time.
> >
> > I hope that all makes sense.
> >
> > Anyhoo.
> >
> > I have read about both the ModelLocator and also
> > ViewHelper/ViewLocator, and am yet to have that warm and fuzzy moment
> > where everything just suddenly makes sense, and thus know which is to
> > be used where.
> >
> > So my question: What would be the best way to go about handling the
> > change of Views within this application?
> >
> > Thanks in advance,
> > Michelle
> >
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/