I have had some requests and seen some developers asking about managing a ViewStack using the PureMVC StateMachine utility. Slacker is a well known demo detailing how to manage View components using deferred instantiation. Combining this demo and the StateMachine utility is a straight forward route to managing a ViewStack in your PureMVC application. I have knocked up a demo which demonstrates how to achieve this.
The demo is a simple ViewStack managed by a toggle menu bar. There are 3 states:
- Login
- Admin/User
- Admin only
The second and third views are dependent on the users role once correctly logged in e.g. the menu bar will restrict access to admin only for the third view. There is a 10 second session timer which will automatically log the user/admin out and return them to the login screen.
The two main elements to point out here are how the StateMachine utility is actually managing the access to the ViewStack checking (1) if the user is correctly logged in and (2) the logged in users role. This is initiated in the Finite State Machine definition (XML) like so:
-
<state name={StateConstants.STATE_3} changed={ ApplicationFacade.CHECK_LOGGED_IN } entering={ ApplicationFacade.CHECK_ADMIN }>
For example, when the ApplicationFacade.CHECK_ADMIN notification is sent, the PureMVC framework will handle the check user logic and the StateMachine.CANCEL notification will manage the transition to the next state (or not, dependent on a your criteria to proceed to the next state).
Have a dig around and feel free to ping me with any questions.
*NOTE*
This is an amended version of the StateMachine, please refer to the following forum post for details.
View source enabled


4 Comments
Cool Simon!
But the view source is not enabled.
Ondina
Odd its fine my end in Safari?? Regardless, its obviously not functioning correctly somewhere so here ya go:
http://www.nutrixinteractive.com/apps/flex/slackermachine/srcview/index.html
It's a Flash Player issue.
With FlashPlayer 10 it works fine (Firefox on Windows, Safari and Firefox on Mac OS)
With FlashPlayer 9 it only works if the mouse cursor is inside of an editable input field...odd enough.
Anyway thank you for the code. It looks good at first sight. It is easy to understand and to follow the logic through the code. The level of difficulty is actually optimal, neither too easy nor too advanced.
I think, your example will help me a lot.
Cheers
Ahhh gotcha, thanks for that man and cheers for the feedback!
One Trackback
[...] has been a topic I have wanted to mention for a while now, actually since my Combining the PureMVC StateMachine Utility with Slacker post as I use this particular logic in there. When I first used a MVC framework primarily PureMVC [...]