Swiz, AS3-Signals, and [Inject] FTW
AS3-Signals is a recent project by Robert Penner as an alternative to Flash Player’s native event system. While I don’t personally have (m)any problems with events, I have been curious about Signals and keeping an eye out for an opportunity to try it, especially in conjunction with Swiz. That opportunity presented itself a few weeks ago, when Joel Hooks finally showed me the world that Robotlegs can be used without extending framework classes all over the place. As he says in the post, I had been asking to see that for a long time, because I cringe at frameworks that mandate lock-in via inheritance.
In looking at Joel’s sample application (which I think is very good), I noticed that it was very similar to a Swiz application. The application is configured using a context class, which is virtually equivalent to a Swiz instance used to configure an area of a Swiz application (or a whole application). So I spent about 15 minutes and took the latest Swiz SWC I had, created a Swiz instance that mapped to his context, put it in the context’s place, and voila; I had the same application running on top of Swiz. Literally the only other thing I had to do was to add a single [PostConstruct] metadata tag. You can see the striking similarities below. Edit: I have now also included the same Swiz configuration as it would look in ActionScript.
Swiz config in MXML
RobotLegs config
Swiz config in ActionScript
You can even take the resulting application and switch the framework it’s running in by simply commenting/uncommenting the ImageGallerySwiz and ImageGalleryContext lines in index.mxml
Working with Signals couldn’t be simpler, and Swiz supports them right out of the box. In fact, I couldn’t help but be amused by the fact Swiz had better native support for them than RobotLegs did.
They are simply defined in a BeanProvider like any other dependency, and then work as expected. The [PostConstruct] I added was on LoadGalleryCommand’s execute() method, and it replaces the last line of ImageGalleryContext’s startup() method.
Summary
I really like the fact that applications can be somewhat interchangeable between the two frameworks now that we’ve settled on [Inject]. I think a reasonable degree of portability is a sign of a good framework, and based on this example you can see that both RobotLegs and Swiz meet that criteria. The obvious question then, is why pick one over the other? Some of it surely comes down to personal preference, but beyond that I think it is a question of power, scalability, adaptability and developer productivity. In future posts, I will show how Swiz is the clear winner in those categories.
Enjoy!
Recent Comments