PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: gordonp on August 08, 2009, 07:42:24

Title: How can I trace the Transition Action called during a state machine transition?
Post by: gordonp on August 08, 2009, 07:42:24
Take the following state machine code example
<state name={STATE_ONE}
<transition action={ACTION_FOO} target={STATE_TWO}/>

<state name={STATE_TWO}
<transition action={ACTION_BAR} target={STATE_TWO}/>

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

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.

Title: Re: How can I trace the Transition Action called during a state machine transition?
Post by: puremvc 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.