Home / Project & Story

Back-End: Function Chains in AS3

 

This class allows for function-chains which can consist of any combination of methods, listeners, tweens and wait-commands, which can either be executed as a top-down list or parallel.

We are lately pepping up our code-base by making it more modular. Things get cluttered very easy if you have to deal with a lot of asynchronous interdepending data.
Imagine you’d like to implement two distinct, independent methods to first load some 3D-models and then load their according textures. In AS3 you would basically create two loader-objects, one for the 3d-model and one for the texture. The first loader would then receive a COMPLETE- or INIT-event-listener pointing to the next loader, which would then load the textures and finally (on receiving another complete-event) do something with all those data. Pretty bound at the hip, if you don’t want to end up with anonymous listeners, which is not recommended. And it’s pretty much the same if you use a multi-loader (like Arthur Debert’s great BulkLoader) and listen to either the completion of the whole bulk or its parts. What if you want to keep all methods self-contained?

Enter Yoshinori Munehara’s Chain-class. This class allows for function-chains which can consist of any combination of methods, listeners, tweens and wait-commands, which can either be executed as a top-down list or parallel. Yoshinori’s work seems to be virtually unknown in the west since everything is unfortunately explained in Japanese only. Still, we highly recommend Chain.as—if you take a few minutes to look at the source-code and the examples, it’s pretty easy to figure out how it works.

In our case, we used this to decouple a lot of our loader-methods, which are now neatly self-contained and can be called and combined freely by a front-controller with a chain. Bulkloader and Yoshinori’s chain work together like a charm. 

Back to the main page

Comments & Trackbacks

Please leave us your comments on this topic.

Commenting is not available in this weblog entry.