I built a ViewController class that I use to switch views.  It simply
listens for CairngormEvents and changes state when it hears one it
likes.  I literally copied the code in FrontController, made it extend
Canvas, and changed the functionality from handling commands to simply
storing string state names.  It works realty well, and you can use as
many ViewControllers in your application as you like.

 

For example:

MyFrontController.as

...

      addCommand(ProductEvent.ADD, AddProductCommand); //
add/edit/insert/update/delete, add resets the currentProduct to a new
instance

...

 

MyViewController.mxml

...

      addView(ProductEvent.ADD, "productForm"); 

...

      <mx:states>

            <mx:State name="productForm">

                  <mx:AddChild>

                        <product:ProductForm />

                  </mx:AddChild>

            </mx:State>

      </mx:states>

...

 

I have one main ViewController that sits right inside my Application
file, one of the states of my main ViewController is a wizard for
creating a new Project (in this instance), the content of that state is
a <wizard:ProjectWizardViewController />, which again simply listens for
the right CairngormEvents and switches the presentation layer as
necessary.

 

While the main ViewController does nothing but switch states, my
ProjectWizardViewController actually does a bit of "local layout" to
standardize the different steps in the Wizard.

 

It works really well, the only thing I would like to add to it is some
way of passing the event down to any Component added via AddChild.  I'm
sure it's not much of a challenge, I haven't found a use for it yet
though.

 

Having the option of having one event both execute business logic, and
switch views, or only one or the other seems to be a very flexible way
of configuring your application.

 

Jay Proulx

[EMAIL PROTECTED]

 

Reply via email to