State Machine Codegen in Actionscript 0.2

I’m learning Actionscript and have ported my state machine code generation engine over to support the language. You can now generate state machines just like you could for my other languages. Check out my Grass Roots Code Generation page for the code.

This is a v0.1 release. It provides all the features supported in my other languages, but I’m thinking that I want to add support for additional features.

  • I’ll probably add onexit() capability. That’s pretty easy to add.

  • I’m debating about do() functionality. This is an internal action that executes continuously inside the state. I’m normally not a fan of this capability for several reasons. The two significant downsides is that the do() feature takes away the event driven characteristics of the design. After all, if you’re using a state machine you’re probably doing something with events. The second downside is that Actionscript is single threaded (or run-to-completion, if you prefer). Coded poorly, single threaded applications can be quite unresponsive. In its favour, Actionscript has an event handling system (see next point) and good timer support. So, I might implement a modified do() that operates with timers, rather than continuously.

  • Actionscript has a nice event handling system. I haven’t integrated the event handling system into the state machine model yet. This is because some implementations might not want to use the event handling system. However, I think I will write a code generator to wrap the events so the state machine then responds to events. That way you can use either implementation as you please.

So those are the extra features I am considering. I may also need to add more hand crafted code sections into the state classes, but that will come out as I start using the implementation more.

If you try out the code, please send me an e-mail to let me know what you think. I have embedded a flash version of the code below.

Alternative content

Get Adobe Flash player