ActionQueue refactoring for ActionScript 3

30 Sep 2007 - 21:04:19 by ArthurClemens in ActionScript3
We are working at an ActionScript 3 rewrite of the framework. One of the joys of a big rewrite is that you get see your work in a new light. We are getting the joys - and pains - of critically reviewing our own classes. Out of user mode, back into architectural mode.

I need to add that ASAP is hardly a framework in the classical sense. It does not imply a coding method, and we consider it more of a practical collection of classes. Because we hardly have dependencies between classes the refactoring job is not that difficult.

But still, some classes like MovieManager and ActionQueue are heavily used so they deserve a more scrutinizing look.

Our co-developers at Lost Boys have argued they want to have more compile checking on the code. Now, the way to add actions to a queue is to list parameters as comma-separated list. ActionQueue blindly passes these parameters to the time-based function. No compile checks whatsoever. But it leads to easy-to-read code. For example, to fade in a MovieClip in 2 seconds from the current alpha value to 100 using an ease-in effect, you write:

var CURRENT:Number = null;
queue.addAction( AQFade.fade, my_mc, 2, CURRENT, 100, Regular.easeIn );

These 2 constraints have been holding me for the last couple of days. After several blank slates I found a compromise that is compile checked AND fairly easy to read:

var CURRENT:Number = Number.NaN;
queue.addAction(new AQFade().fade(my_mc, 2, CURRENT, 1, Cubic.easeIn ));

Note the small changes that are inherent to AS3.

I even could go as far as using a static function only:

queue.addAction(AQFade.fade(my_mc, 2, CURRENT, 1, Cubic.easeIn ));
... but that would complicate the helper classes too much. I really want to have transparent helper classes - anybody should be able to write these.

I have rewritten the ActionQueue engine completely. Perhaps it is faster (I haven't tested this), but in any case a lot easier to debug and add onto. In the meantime I have added a number of goodies:

  • Marker insertions. You can use these to check if a queue has passed a marker.
  • Markers also spawn events, so you know when a marker is passed.
  • An (optional) ActionQueueController that checks a condition before allowing a queue to pass.
  • Looping made easy.

Get a taste from this demo:

Comments

 

Topic revision: r1 - 30 Sep 2007 - 21:04:19 - ArthurClemens
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding ASAP? Send feedback