To make our lives a little bit easier I was looking for a simple class that we can use to sequence those tasks. I looked around but couldn't find anything that was small, simple to fit our needs. So I wrote one called SimpleSequencer.
The class is not supadupa cleaned up but it works great and I've used it heavily in some of our recent projects.
This is how it works:
Create a new SimpleSequencer Instance. (The String you pass in the constructor is only used as for debugging at the moment.)
var sequence:SimpleSequencer = new SimpleSequencer('id');Add a Listener to Event.COMPLETE.
sequence.addEventListener(Event.COMPLETE, _onComplete_handler);Add steps to your sequence using the addStep function.
addStep($stepId:Number, $target:EventDispatcher, $functionToCallToStart:Function, $eventToListen:String, $args:Object=null);The order in that you add your Steps does not matter. The steps get sorted by the $stepId:Number. All steps with the same $stepId get called at once. It starts the next stepId after all tasks within one StepId are completed.
$target is the class instance that throws the $eventToListen-Event once the task is completed.
$functionToCallToStart is a reference to the function that starts the task.
Example:
sequence.addStep(100, myAnim, myAnim.startAnimation, Event.COMPLETE);At the moment there are two additional arguments that you can add.
//add a delay to the $functionToCallToStart
sequence.addStep(1.5, myAnim, myAnim.animateIn, Event.COMPLETE, {delay:5000});
//add arguments to pass to $functionToCallToStart
sequence.addStep(3, loader.contentLoaderInfo, loader.load, Event.COMPLETE, {functionToCallParams:new URLRequest('myFile.swf')});
The SimpleSequencer lets you sequence almost all tasks. And it's worked pretty well for me so far. I think I'm gonna blog some more examples and add more comments to the class soon. But for now, here is it:
SimpleSequencer.as
Let me know what you think.



