Hi,
ben.clinkinbeard wrote:
> Depending on user choices, I need to instantiate and attach one of
> several chunks of UI and related functionality (basically glorified
> ViewStacks) in my Cairngorm based app. I know that Commands and the
> model are supposed to be completely separated from the view, but I am
> having a hard time thinking up a way to accomplish this.
>
> Basically, when the user selects a certain task, I need to attach a
> set of screens to the stage and allow them to begin working. If they
> later choose a different option, I need to remove the existing stack
> and attach the new one. I am not using Modules due to the lack of a
> mature approach in Cairngorm based apps, and an accelerated timeline.
> My thinking is that I need at least a single Command with a reference
> to the parent component I will attach my screens to.
>
> Thoughts?
Sounds reasonable, my question is how you would get the reference to the
parent component in the Command? And what if your event needed to update
more than one view?
Another option to consider is to add an event listener to the CG
dispatcher and handle the event in the component that is controlling the
view without using a Command.
ie) something like:
class ViewStackContainer extends Panel{
public static const VIEW_CHANGE:String = "VIEW_CHANGE";
public function creationComplete() {
//Handle the event here rather than via the CG controller.
CGEventDispatcher.getInstance().addEventListener(
VIEW_CHANGE,
handleViewChange);
}
function handleViewChange(e:Event) {
//ChangeViewStack here as requested.
setCurrentView( e.data.viewIdentifier );
}
//end ViewStackContainer class
}
class ViewSelector extends PopupButton{
function dispatchViewChangeEvent() {
var e:CaringormEvent = new
CairngormEvent(ViewStackContainer.VIEW_CHANGE);
e.data = viewIdentifier;
CGEventDispatcher.getInstance().dispatchEvent(e);
}
//end ViewSelector class
}
I'm still coming to grips with CG and view manipulation so i dunno if
there is "better" way.
HTH.
shaun