Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: 1 ... 4 5 [6] 7 8 ... 10
Print
Author Topic: StateMachine - A PureMVC / AS3 Utility  (Read 166552 times)
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #75 on: March 03, 2009, 06:53:18 »

I think you'll like it. I'm loving it!

When I dived into my cuurent project, I was determined to use it since I hadn't had a chance to really apply it beyond the Stopwatch demo.

I was somewhat crestfallen to find that the big hole in that demo was the fact that all the state changes are initiated by the user's button presses. No code is ever executed that programmatically initiates a state change.

The reason that's a problem is that the Stopwatch instantly falls into a basin of stability when the new state is reached and so will always be ready for the next action to carry it to another state.

However in the real world, you want to do automated things like check for net connectivity, then check for a license, branch off and collect the license frome the user if not present, then return to checking its validity, then load stuff, then display the main user interface.

For my current app I had lots of that business going on and I felt the StateMachine would be perfect for keeping track of where we were in the process.

But as soon as I started implementing I found that firing off code to do something that would lead to another change of state would fail if triggered by the entering or exiting notes, because, by definition, the new state hasn't been reached, and so when the code you triggered ends up sending an ACTION, the machine ignores it because it was still preparing to enter the state you now wanted to leave.

I was quite pleased to find that adding the per-state changed note was enough to fix the problem.

Then being able to tunnel data through to the next state really helped to not make it so hard for the next state to know what's going on. For instance, when the license info isn't present, and I go collect it with a little data entry panel, then the mediator for the panel stuffs the info collected into the body of the ACTION note which the command kicked off when the state is changed to the license saving state simply plucks out the data from the note, stores it in the AIR ELS and then fires the ACTION for verifying the stored license. If that license is bad, your ping ponged back to the license entry state and do it all again until you get it right, then you move on through to the next state. When the app comes up again, the good data is stored and you never pass through the license entry and saving states.

It really is like a well-oiled machine now. I love it!

-=Cliff>
Logged
Neil Manuell
Courseware Beta
Sr. Member
***
Posts: 109


View Profile Email
« Reply #76 on: March 03, 2009, 07:04:26 »

Yes, I've found myself making hacky workarounds
am about to start a new project and will def be using it in that

Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #77 on: March 03, 2009, 08:35:01 »

Thank you Neil for the utility.
Thank you  Cliff for the changes.

from http://trac.puremvc.org/Utility_AS3_StateMachine/wiki/ReleaseNotes:

Passing data between States. When sending a StateMachine.ACTION notification, you may include any Object as the body of the notification and it will be included in the state-specific 'exiting', 'entering', and 'changed' notifications. This allows, for instance, the data collected from a UI form in the 'DATA_ENTRY' state to be passed to the 'DATA_SAVING' state when the form's 'Save' button is pressed, for instance.

This is really very useful!!

A more 'real-world' demo will be forthcoming.

I know, I know. You are very busy:)
But I can't stop myself from asking: when?
Can you give us an approximate time frame? 1 week, more weeks, 1 month?
Logged

~ Ondina ~
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #78 on: March 04, 2009, 06:01:53 »

Hi Ondina,

I was actually thinking about this as I was waking this morning. Its an important thing to get out there and will happen.

However, I'm full-on busy at the moment, I just can't say, though I wish I could. If it weren't for the pesky business of having to actually do other stuff for a living I'd get way more done here. :(

-=Cliff>
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #79 on: March 04, 2009, 07:11:19 »

However, I'm full-on busy at the moment, I just can't say, though I wish I could. If it weren't for the pesky business of having to actually do other stuff for a living I'd get way more done here. :(

Try to spend a little time solving the problem of human cloning. Work that out and all your time problems will go away ;)
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #80 on: March 04, 2009, 07:41:28 »

Hey Cliff


After I wrote the previous post I found Neil's example:

http://revisual.co.uk/?tag=statemachine

which is cool also because it combines StateMachine with the AsynchCommand ,  but it's the old version of StateMachine and I still don't know how to apply it to CRUD operations.


I was actually thinking about this as I was waking this morning. Its an important thing to get out there and will happen.

That's because people like me who want this cool utility  so badly, think intensively  about it while you are sleeping.;-)


However, I'm full-on busy at the moment, I just can't say, though I wish I could. If it weren't for the pesky business of having to actually do other stuff for a living I'd get way more done here.
I  know what you are talking about.
And how short a day is when you want to have lots of things done by the end of the day.

Actually I kind of feel bad right now.  I'm trying to use your framework and those utilities for my current project  (that I'm working on for a living) while you guys support us ( the community) for free in your spare time. There should be  a “Donate” section on the web-site. It wouldn't make you rich, but maybe it would help you cover the costs for the website?


Oh  I just saw the better solution that Jason suggested.
I also say YES to Cliff's cloning
( 1564-1 = 1563 clones needed?)
Logged

~ Ondina ~
Neil Manuell
Courseware Beta
Sr. Member
***
Posts: 109


View Profile Email
« Reply #81 on: March 04, 2009, 09:27:55 »

I'll see if I can update those demos for the latest build...

though, they might not be more useful than they are at the present
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #82 on: March 04, 2009, 09:43:57 »

Thank you Neil.

In the meantime I'll look at periplum, that reminds me of Cirque du Soleil:)
Logged

~ Ondina ~
gjastrab
Jr. Member
**
Posts: 18



View Profile WWW Email
« Reply #83 on: March 05, 2009, 02:18:38 »

Don't hold your breath on the demo. I'm steaming on a project that you'll all hear much more about very soon. I will be working on something, but spare time is low right now.

Hey everyone, I just pushed up a demo utilizing these new changes in StateMachine to github.  Please check it out there until Cliff moves it into a demo page here (if he thinks its worthy)  ;)

http://github.com/gjastrab/puremvc-statemachine-1.1-login-demo/tree/master
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #84 on: March 06, 2009, 01:57:03 »

Hey Greg,

I've downloaded your example. Yes, it is useful, at least for newbies like me!!

I'm going to play around with it and see how I can use this “changed” state with notifications for other states.

If you already know how to use the new features of the StateMachine why don't  you try to modify the EmployeeAdmin  or CafeTownsend example as a next level of complexity regarding the StateMachine?
I know it's too much to ask.

Anyway thank you very much for your example:)
Logged

~ Ondina ~
Paul Bonneville
Newbie
*
Posts: 1

 - retrometroltd
View Profile Email
« Reply #85 on: March 06, 2009, 09:49:03 »

Where is the most appropriate place to list the State/Action state machine constants for your application for a strictly AS3 implementation? I'm thinking is should be the main application facade.

The examples I have found are all Flex based and I've seen the constants placed in the main flex application file (StopWatch example) and then in the main application facade in the most recent LoginFSM example.

Also, being a newbie to AS3 and PureMVC, the LoginFSM has a nearly one-to-one correlation between notification constants, states and actions. In a typical PureMVC implementation this would not necessarily be the case since there are only a finite number of application states to move between but a vast amount of application notifications between all the Mediators, Controllers and Proxies depending on your application's complexity. Not all the application notifications are going to affect the state. I am looking more for an affirmation of what I just stated as opposed to trying to make a statement. Do I have it right?

It gets a little tricky jumping between Flex and Flash PureMVC examples since we are dealing with either the main Stage (AS3 project) or the main Application (Flex project).

Also, what is behind the convention of appending notification names with "actions/", "states/" etc. Again, it seems to imply a direct correlation between notifications and state changes and I'm pretty sure that is not going to be the case in the real world. It looks like any application notifications that also trigger state changes would be best served by this "appending" naming convention.

I understand the simplicity of the LoginFSM demo, but as someone who is "green" to PureMVC, I want to be sure that I am interpreting things correctly.

Ultimately I am asking if I am interpreting things correctly.

Any input would be appreciated, even if it's just "You're on the right path."

(If I get the hang of PureMVC over the next few weeks I will probably put together a bit more comprehensive AS3-only demo)

Thanks!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #86 on: March 07, 2009, 08:00:35 »

I keep thinking of that movie Multiplicity and how it would probably end up like that. :)
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #87 on: March 07, 2009, 08:17:15 »

Hey Doug

How is Doug doing?
Logged

~ Ondina ~
guyinthechair
Newbie
*
Posts: 2


View Profile Email
« Reply #88 on: March 20, 2009, 08:22:25 »

My advice is Flex only, so take from it what you can.

Where is the most appropriate place to list the State/Action state machine constants for your application for a strictly AS3 implementation? I'm thinking is should be the main application facade.
This is up to you, but I like to define my constants in my concrete "State" view classes. For example, if I use a ViewStack at the Application level to separate the states, each child of my ViewStack would be considered a State class. I wrote an AbstractState (extends Canvas) that my concrete State view classes extend, these states have enter/exit actions by default defined in AbtractState, then I have a mediator to listen for StateMachine notifications and coordinate the application state changes. But I digress.

The examples I have found are all Flex based and I've seen the constants placed in the main flex application file (StopWatch example) and then in the main application facade in the most recent LoginFSM example.
The StopWatch demo defines State Machine constants similarly to what I described above.

Also, being a newbie to AS3 and PureMVC, the LoginFSM has a nearly one-to-one correlation between notification constants, states and actions. In a typical PureMVC implementation this would not necessarily be the case since there are only a finite number of application states to move between but a vast amount of application notifications between all the Mediators, Controllers and Proxies depending on your application's complexity. Not all the application notifications are going to affect the state. I am looking more for an affirmation of what I just stated as opposed to trying to make a statement. Do I have it right?
Sort of. It's true that you can send any string as the name for a notification. So you could potentially mix up some of your application notifications with notifications sent by a PureMVC utility like the StateMachine. But this is why they try to conform to unique notification names (like "StateMachine/notes/action").
Here's how I generally will define the constants in my concrete State view classes:
:
public class MainState extends AbstractState{
public static const NAME:String = "MainState";
public static const ENTER:String = "Enter" + NAME;
public static const EXIT:String = "Exit" + NAME;
public static const CHANGED:String = "Changed" + NAME;
public static const GOTO:String = "Goto" + NAME;
}

Also, what is behind the convention of appending notification names with "actions/", "states/" etc. Again, it seems to imply a direct correlation between notifications and state changes and I'm pretty sure that is not going to be the case in the real world. It looks like any application notifications that also trigger state changes would be best served by this "appending" naming convention.
Yes, and... yes. I think we're on the same page here...

I understand the simplicity of the LoginFSM demo, but as someone who is "green" to PureMVC, I want to be sure that I am interpreting things correctly.

Ultimately I am asking if I am interpreting things correctly.

Any input would be appreciated, even if it's just "You're on the right path."

(If I get the hang of PureMVC over the next few weeks I will probably put together a bit more comprehensive AS3-only demo)

Thanks!
You're on the right path as far as I can tell. Notifications are generic messages that can be listened for an interpreted by anybody. The convention of naming notifications a certain way is only to avoid conflict between Utility code and your custom code. Happy coding!
Logged
deltajam
Courseware Beta
Full Member
***
Posts: 25


View Profile Email
« Reply #89 on: March 23, 2009, 05:52:57 »

From my reading, it looks like this utility is more for application states ... than view states.  Is there a proper way to handle view states with the State class?
« Last Edit: March 23, 2009, 05:55:27 by deltajam » Logged
Pages: 1 ... 4 5 [6] 7 8 ... 10
Print