StateMachine Setup Error

kyle's Avatar

kyle

27 Oct, 2009 09:54 AM

Hi Guys,

[Hope i'm placing this in the correct place!]

I used the StateMachine all the time in PureMVC and was stoked to see it used in RobotLegs.
But on my first attept to implement it i have run into an error, which could quite likely be something im doing incorrectly.

    override public function execute():void
    {
        var fsm:XML = 
        <fsm initial={LoadupEvent.STATE}>
            <state name={LoadupEvent.STATE} entering={LoadupEvent.ENTER} exiting={LoadupEvent.EXIT} changed={LoadupEvent.CHANGED} />
        </fsm>;         

        var stateMachine:StateMachine = new StateMachine();
        var fsmInjector:FSMInjector = new FSMInjector(fsm);

        injector.injectInto(fsmInjector);
        fsmInjector.inject(stateMachine);
    }

This is throwing the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at org.swiftsuspenders::VariableInjectionPoint/applyInjection()[/Users/tschneidereit/dev/swiftsuspenders/swiftsuspenders/src/org/swiftsuspenders/VariableInjectionPoint.as:48]
    at org.swiftsuspenders::Injector/injectInto()[/Users/tschneidereit/dev/swiftsuspenders/swiftsuspenders/src/org/swiftsuspenders/Injector.as:113]
    at com.freeworldcoatings.intranet.controller.controls.prep::PrepStateMachineCommand/execute()[C:\dev\Freeworld Intranet\site\src\com\freeworldcoatings\intranet\controller\controls\prep\PrepStateMachineCommand.as:29]
    at org.robotlegs.base::CommandMap/routeEventToCommand()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/CommandMap.as:151]
    at <anonymous>()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/CommandMap.as:102]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.freeworldcoatings.intranet::ApplicationContext/startup()[C:\dev\Freeworld Intranet\site\src\com\freeworldcoatings\intranet\ApplicationContext.as:35]
    at org.robotlegs.base::ContextBase/initialize()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/ContextBase.as:120]
    at org.robotlegs.base::ContextBase()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/base/ContextBase.as:83]
    at org.robotlegs.mvcs::Context()[/Users/shaun/Documents/Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/robotlegs/mvcs/Context.as:43]
    at com.freeworldcoatings.intranet::ApplicationContext()[C:\dev\Freeworld Intranet\site\src\com\freeworldcoatings\intranet\ApplicationContext.as:23]
    at Main/init()[C:\dev\Freeworld Intranet\site\src\Main.as:25]
    at flash.display::DisplayObjectContainer/addChild()
    at Preloader/startup()[C:\dev\Freeworld Intranet\site\src\Preloader.as:43]
    at Preloader/checkFrame()[C:\dev\Freeworld Intranet\site\src\Preloader.as:33]

Any ideas? ......... also i have just moved from using the "Proxy' version of RL to the 9.5 release.

Cheers
Kyle

  1. Support Staff 2 Posted by Joel Hooks on 27 Oct, 2009 02:22 PM

    Joel Hooks's Avatar

    I'd need to see more code, but I didn't test the FSM against a single state. I will add that to the unit tests and see if I can reproduce the error. I also didn't test against the entering position, so I will do that also. Thank you for providing some cases ;)

    This is what I'd consider the minimal setup for the state machine (as it is now):

        <pre>private var fsm:XML =
            <fsm initial={STARTING}>
    
                <!-- THE INITIAL STATE -->
                <state name={STARTING}>
    
                   <transition action={STARTED} 
                               target={CONSTRUCTING}/>
    
                   <transition action={START_FAILED} 
                               target={FAILING}/>
                </state>
    
                <!-- DOING SOME WORK -->
                <state name={CONSTRUCTING} changed={CONSTRUCT} exiting={CONSTRUCTION_EXIT}>
    
                   <transition action={CONSTRUCTED} 
                               target={NAVIGATING}/>
    
                   <transition action={CONSTRUCTION_FAILED} 
                               target={FAILING}/>
    
                </state>
    
                <!-- READY TO ACCEPT BROWSER OR USER NAVIGATION -->
                <state name={NAVIGATING} changed={NAVIGATE}/>
    
                <!-- REPORT FAILURE FROM ANY STATE -->
                <state name={FAILING} changed={FAIL}/>
    
            </fsm>;</pre>
    
  2. 3 Posted by kyle on 27 Oct, 2009 02:37 PM

    kyle's Avatar

    This is the project so far, i only have two states.

  3. Support Staff 4 Posted by Joel Hooks on 27 Oct, 2009 03:38 PM

    Joel Hooks's Avatar

    LoadupMonitorEvent is missing from the archive, and there is an error
    in LoginView.as at line 50 calling a class, loginMC().

    I think also that using event constants for the state constants is
    probably a bad idea, as the state machine is utilizing the central
    event bus. This could very well introduce conflicts. Better to just
    have a static StateMachineConstants class that defines these states:

    http://github.com/joelhooks/robotlegs-examples-UnionPlatformChatClient/blob/master/src/org/robotlegs/examples/bootstrap/AppConfigStateConstants.as

    here is an example of that.

  4. Support Staff 5 Posted by Joel Hooks on 27 Oct, 2009 04:34 PM

    Joel Hooks's Avatar

    Hey Kyle,

    I gutted out some stuff just to show the FSM in your app as it cycles through some states. I've attached the src folder.

  5. 6 Posted by kyle on 28 Oct, 2009 06:56 AM

    kyle's Avatar

    Hi Joel,

    Thanks for the feedback and help.
    I like the StateMachineConstants idea and will now implement it!

    In your refleshing you code:

            var stateMachine:StateMachine = new StateMachine(eventDispatcher);
    

    But in the versions of statemachine i have, from git, the statemachine doesnt take a constructor parameter. Presumable i have the wrong version?

    Cheers
    Kyle

  6. Joel Hooks closed this discussion on 29 Oct, 2009 06:46 AM.

  7. Joel Hooks re-opened this discussion on 29 Oct, 2009 06:47 AM

  8. Support Staff 7 Posted by Joel Hooks on 29 Oct, 2009 06:47 AM

    Joel Hooks's Avatar

    I emailed a reply, I guess it didn't go through, but yes, that was an older version.

  9. Joel Hooks closed this discussion on 29 Oct, 2009 11:35 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac