PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: masterkrang on November 30, 2010, 11:15:05

Title: Managing view states
Post by: masterkrang on November 30, 2010, 11:15:05
I'm building a test air app in Flash 5 Professional and had a couple of questions. I wonder how you guys are dealing with the different view states? Since I'm not in Flex or Flash Builder and don't have access to the different view states, I'm wonder what is the best way to control them in the Flash / PureMVC world. My application has a few simple states that need to either show or hide at different times. It's pretty simple, only one of a few views will be showing at any time.

The way I'm thinking to do it is to have the main application, or ApplicationMediator keep track of times. These transitions won't be fired by user clicks, only will be fired based on different times during the day. After the time is reached, I plan to fire events telling what state the app is in, like ApplicationFacade.StateOne, ...StateTwo (of course naming these events a bit more in accordance with the actual view for each state). Then have each Mediator interested in an ApplicationFacade.ViewStateChange event, passing along with a note saying which state should show it self (at which point, all others would hide and possibly destroy themselves).

Would this be a good way to go about doing it? I'm interested in hearing how others are dealing with multiple view states from the PureMVC perspective.

Title: Re: Managing view states
Post by: puremvc on December 01, 2010, 02:53:35
In a Flex app, I like to have the StateMachine utility control my application states and have mediators in charge of hearing about those changes and coordinating the appropriate view states. It's nice to have states in Flex, but not necessary. You can encapsulate the states of your views in your view component classes and expose methods that mediators use to trigger view state changes, and events you dispatch that tell your mediators about the view state transitions completing and the like.

There is a short introduction to the utility at http://puremvc.tv


Title: Re: Managing view states
Post by: masterkrang on December 06, 2010, 09:43:33
You say it's nice to have state in Flex and I think you're right. I'm sort of stuck in a situation where I need to decide whether I can learn StateMachine really fast or just implement Flex states project. What would you recommend? I can only guess I'll be back with questions aboutStateMachine...

Title: Re: Managing view states
Post by: puremvc on December 09, 2010, 08:13:42
Even with a Flex states project, the StateMachine is useful as it keeps application state, not view state. With Flex the the nice thing is you have a handy way to deal with view states already. That's half the game. Combine it with the StateMachine and you've got the full monty, so to speak.

If you're only using Flash, you can still use StateMachine, you just need to implement view states yourself.