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 [2] 3 4 ... 10
Print
Author Topic: StateMachine - A PureMVC / AS3 Utility  (Read 109919 times)
Neil Manuell
Courseware Beta
Sr. Member
***
Posts: 109


View Profile Email
« Reply #15 on: December 29, 2008, 04:31:40 »

mmmm this is quite a pertinent question, as it involves an asynch element.

The fact that the StateMachine Util is itself synchronous, must be taken into account. The important thing is not to fire an async command from the exiting notification of a State (and I see no reason why this should be needed, these should merely provide 'clean up' functionality).  It is likely that this will mean that the enter Notification of the next state is fired before the asynch process of the exiting State has finished.  The Synchronous nature of the StateMachine can be worked with by encapsulating asynch processes into separate states.

These are two methods that I have employed myself:

             MainState
              |        ^
   (loadAssets) (loadComplete)
              V        |
             LoadState

or

             MainState
               |      ^
   (loadAssets) (loadError)
               V      |
            LoadState
                 |
         (loadComplete)
                 V
           DisplayState

This also allows restriction of user activity within the loading state, and ensures that a view can be bound to it (ie a prog bar).

hope that helps :~)
« Last Edit: December 29, 2008, 04:42:41 by fleecie » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #16 on: December 29, 2008, 07:02:58 »

Note that though the StateMachine is synchronous, you can use the AsynchCommand utility in conjunction with it to cause asynch processes to complete before the state transition completes.

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


View Profile Email
« Reply #17 on: December 29, 2008, 07:12:57 »

Hey cliff,

surely if you use the AsynchMacroCommand, on an exit Notification, as soon as the executing code hits an AsynchCommand (and added a handler), it will continue back down the call stack, to the StateMachine, and send the enter notification for the next state, then run any code registered for it, and only when the entire thread has completed, will it be able to execute the handler for the exiting AsynchCommand, allowing the AsynchMacroCommand to continue.

I'm by no means an expert on the execution order of AS3 code, but the above was my understanding of it.  I also have to admit that I haven't actually tried it, as I didn't think it would work :~/

« Last Edit: December 29, 2008, 07:15:32 by fleecie » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #18 on: December 29, 2008, 05:59:39 »

Fleecie,

You may be right. I haven't tried it yet either, but thought it would work because the thread of execution shouldn't return to the StateMachine until the AsyncMacroCommand completes its execute method, which cannot happen until all its subcommands have completed.

We have seen in the Sequential demo that asynch timer processes can effectively hold the thread of execution inside an AsynchMacroCommand's execute method until its children, async or not, complete. This shold be no different for asynch service calls.

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


View Profile Email
« Reply #19 on: December 30, 2008, 01:29:06 »

that would be cool :)
Logged
cambiata
Newbie
*
Posts: 6


View Profile Email
« Reply #20 on: January 02, 2009, 06:18:57 »

Hi Cliff and Fleecie!

The asset/media loading stuff is a common "real life problem", and so are service calls. To me it sounds very reasonable to combine these with the state machine paradigm.

A demo combining the state machine and async loading and/or service calls would be of great help for a PureMvc newbee like me!

Regards / Jonas
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #21 on: January 02, 2009, 01:34:27 »

It's definitely on the list of needed stuff. Fortunately they each have separate demos and are learnable. The combination will be powerful to be sure.  I'm fully tied up trying to get video training going at the moment. In the meantime if you (or any other kind soul reading this thread)  manage to get one going let me know.

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


View Profile Email
« Reply #22 on: January 02, 2009, 01:39:11 »

well, I'm working on some thing similar at the mo, and at some point I'll try and rip the guts out to make a simple demo... don't hold your breath tho...:~/
Logged
cambiata
Newbie
*
Posts: 6


View Profile Email
« Reply #23 on: January 03, 2009, 12:31:46 »

Hurry up, Fleecie! My face is already blue!  :) / Jonas
Logged
muqtadir
Newbie
*
Posts: 2


View Profile Email
« Reply #24 on: January 03, 2009, 02:08:30 »

Is there is a concept of interceptor.
How State will work with Pipes Modular approach. -MA

« Last Edit: January 03, 2009, 02:20:21 by muqtadir » Logged
Neil Manuell
Courseware Beta
Sr. Member
***
Posts: 109


View Profile Email
« Reply #25 on: January 03, 2009, 02:16:21 »

I presume you are talking about the Interceptor Pattern
Do you have any resources?
« Last Edit: January 03, 2009, 02:36:39 by fleecie » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #26 on: January 03, 2009, 02:43:43 »

Each core can have its own StateMachine. Within a core, you can respond to any incoming message or interface call by changing the state of the core, which could in turn trigger outgoing messages (or call return value) that cause other modules to change state.

-=Cliff>
Logged
muqtadir
Newbie
*
Posts: 2


View Profile Email
« Reply #27 on: January 03, 2009, 03:01:19 »

Make sense. I have model which is shared by different core. Will try your option to see how it behaves. - MA
Each core can have its own StateMachine. Within a core, you can respond to any incoming message or interface call by changing the state of the core, which could in turn trigger outgoing messages (or call return value) that cause other modules to change state.

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


View Profile Email
« Reply #28 on: January 04, 2009, 02:25:44 »

hey, cambiata,
have whipped up a quick demo here you go.
http://revisual.co.uk/?p=388
Logged
cambiata
Newbie
*
Posts: 6


View Profile Email
« Reply #29 on: January 05, 2009, 06:00:44 »

Thanx a lot, Fleecie!
I've delve into it as soon as my brain has got some oxygene!  :)

Jonas

Logged
Pages: 1 [2] 3 4 ... 10
Print