Combining the PureMVC StateMachine Utility With Slacker

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.

SlackerMachine Demo

View source enabled

This post shows data binding to a mediator from a model which you can read more about here: In some of my states I load in various Modules so ensure you read around Garbage Collection in my post: