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]
Print
Author Topic: How can I trace the Transition Action called during a state machine transition?  (Read 5647 times)
gordonp
Newbie
*
Posts: 5


View Profile Email
« on: August 08, 2009, 07:42:24 »

Take the following state machine code example
:
<state name={STATE_ONE}
entering={ENTER_STATE_ONE}
exiting={EXIT_STATE_ONE}
changed={CHANGED_STATE_TWO}>
<transition action={ACTION_FOO} target={STATE_TWO}/>
</state>

<state name={STATE_TWO}
entering={ENTER_STATE_TWO}
exiting={EXIT_STATE_TWO}
changed={CHANGED_STATE_TWO}>
<transition action={ACTION_BAR} target={STATE_TWO}/>
</state>


How can I trace specifically which transition action caused the state transition?

In other, words how can find out if it was ACTION_FOO or ACTION_BAR that caused a transition to STATE_TWO?

Another way of putting it. Assume ENTER_STATE_TWO is mapped to the following command:

:
package com.app.controller
{
import com.app.ApplicationFacade;

import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.command.SimpleCommand;

public class EnteringStateTwoCommand extends SimpleCommand
{
override public function execute(note:INotification):void
{
                    // Entering guard code goes here
}
}
}

Assume somewhere in my code there are the following notifications sent:
:
sendNotification(StateMachine.ACTION, null, ACTION_FOO);

...

sendNotification(StateMachine.ACTION, null, ACTION_BAR);



How can I query which specific ACTION brought me to this state when I am in the EnteringStateTwoCommand command? Or anywhere else in the state machine event chain for that matter. Theoretically it could be either ACTION_FOO or ACTION_BAR in the above command.

Maybe I overlooked something but what is the syntax to get the actual value of the transition action itself during a state machine notification? Is it

:
note.getType()
Maybe it isn't possible to get the ACTION in this command? Where and when can I find out about the transition action? I am trying to debug the logic flow in my app's state machine implementation.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 09, 2009, 07:47:58 »

States should be decoupled; unaware of each other. Where you came from should not be of any consequence when you have entered a new State. 

You can pass data from State to State in the note body, but you will not be advised of what the ACTION was in the state-specific changed notification that is fired when you reach a new State.

For troubleshooting, I would suggest using the Flex Builder debugger to step through your code instead of mucking about with trace statements. Just set a breakpoint on the lines that send the ACTION notes and then step through the code manually when the debugger hits the breakpoint.

-=Cliff>
Logged
Pages: [1]
Print