Finite State Machine utility for RL2
Hello All,
I have been using RL1 for some time and love it. I am just now
trying to get my feet wet with RL2. With RL1, I always use the
robotlegs-utilities-StateMachine
utility. But I am not sure if I can still use this utility in RL2
as is or must it be altered to work in RL2? Is there a new better
option for RL2? Thanks!
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
Support Staff 1 Posted by Ondina D.F. on 22 Jun, 2013 07:29 AM
Hello Enders,
Joel stated on github that he removed all dependencies to Robotlegs from the StateMachine. That means you could use it with rl2 as well.
There is also Neil’s statemachine(s) : https://github.com/AS3StateMachine
I can’t say whether it works with rl2 though.
Not the same as a StateMachine, but you might want to take a look at rl2’s Lifecycle:
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...
hth
Ondina
2 Posted by Scott Enders on 22 Jun, 2013 02:35 PM
Hello Ondina,
Thanks for your help. Would it be suggested to initialize the StateMachine related code in an extension?
Support Staff 3 Posted by Ondina D.F. on 22 Jun, 2013 02:57 PM
Hi Scott,
You’re welcome!
Yes, I think it would be a good idea.
Ondina
4 Posted by Scott Enders on 24 Jun, 2013 05:25 PM
Hello again,
I tried initializing the
StateMachine
code in a customIExtension
class, but I was unable to get reference to theIEventDispatcher
from the extension. Trying to inject it would return null. An instance of theIEventDispatcher
is necessary for theStateMachine
class constructor.So, I put the code in an
IConfig
class instead. From the config file I am able to get reference to the eventDispatcher (via injection). I tested out the functionality of theStateMachine
code and it works as expected.I am wondering if this is best practice for such a thing. Is this the way to go or should I have this in an extension? If the extension is best practice, what am I missing to get it to work properly?
Support Staff 5 Posted by Ondina D.F. on 25 Jun, 2013 09:18 AM
Hi Scott,
I think you’ve already read this:
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...
Perhaps you forgot to install YourExtension?
Also, take a look at the various rl extensions, for example:
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...
Let us know if that helped.
Ondina
Support Staff 6 Posted by creynders on 25 Jun, 2013 10:05 AM
TBH I do think it's a good idea to put it in a config file, instead of an
extension. Extensions are like plugins, they should add to the
functionality.
If I remember correctly extensions aren't injected with anything except for
the context as a parameter to the `extend` method.
Which means you could access the Event Dispatcher instance in the `extend`
method with
@@@
context.injector.getInstance(IEventDispatcher);
@@@
But as I said, I wouldn't recommend it.
7 Posted by Scott Enders on 25 Jun, 2013 01:25 PM
@Ondina - Yeah, I did install my extension. The problem was I did not know how to get reference to anything other than the context (via the parameter of extend method). I was trying to inject the eventDispatcher using the Inject meta tag. But it always came back null. I guess injection isn't allowed in extensions.
@creynders - Thanks for the info. I guess I will keep it in the config then. That seems like a better fit.
Thanks for all your help.
Scott Enders closed this discussion on 25 Jun, 2013 01:26 PM.
Ondina D.F. re-opened this discussion on 25 Jun, 2013 02:02 PM
Support Staff 8 Posted by Ondina D.F. on 25 Jun, 2013 02:02 PM
Scott, this should actually work:
Or, like creynders suggested:
9 Posted by Scott Enders on 25 Jun, 2013 08:42 PM
For everyone's benefit, here is the config class I came up with while testing:
Support Staff 10 Posted by Ondina D.F. on 27 Jun, 2013 07:56 AM
Thanks for sharing your solution!
Ondina D.F. closed this discussion on 27 Jun, 2013 07:56 AM.