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:

XML:
  1. <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 entry was posted in Flex, PureMVC, StateMachine and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

4 Comments

  1. Ondina
    Posted May 6, 2009 at 2:51 pm | Permalink

    Cool Simon!

    But the view source is not enabled.

    Ondina

  2. Posted May 6, 2009 at 2:57 pm | Permalink

    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

  3. Ondina
    Posted May 6, 2009 at 4:42 pm | Permalink

    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

  4. Posted May 6, 2009 at 4:47 pm | Permalink

    Ahhh gotcha, thanks for that man and cheers for the feedback!

One Trackback

  1. By DataBinding a Proxy to a Mediator on March 1, 2010 at 1:01 pm

    [...] 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 [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • FreeAgent sign-up


  • Recent Posts

  • Categories