Why start with the last package ? Because this sequencing package holds a concept that is used on many parts of the library. So, by using other parts of the library, you may use/need to know what’s going on.
Description
The idea is simple. You have 3 mains objects, an 1 interface to know. Those main objects are kind of “managers” for a stack of tasks to execute. Tasks can be whatever you want, from a loading task to a tweening one. Main objects are : Sequence, Group, and Queue. Interface for a task is Stackable.
• A sequence is an object that executes one task by one task :
• A group executes all its tasks in parallel :

• A queue is a mix of sequence and group. It executes N tasks of a stack in parallel, and pick an other task of the stack when a task ends until the queue ends :
To quickly highlight the benefits of each, think that each task of the images above are actually assets. The width of the image represents the amount of time to complete the tasks, but the height represents a kind of how slow your downloads will be, because of the parallelism of the tasks.
The black line represents when those 3 types of objects dispatch an event : when their stack of task is finished.
• The Stackable interface represents an object that can be stored in a stack of tasks.
A nice thing to notice is that Sequence, Group ans Queue are Stackable. So you can make sequences of sequences, groups of sequences, sequences of queues, or whatever that may fit your needs at any time.
Because of the daily use, i already made Stackable objects :
• Load, which attempts to uniform in a unique way most of the loaders of the flash APi, Loader, URLLoader, Sound.
• Message is a Stackable AMFphp call.
• Call is a single function call with custom arguments. It looks useless alone, but it can be very handy embedded into a stack.
• Delay makes a pause into a stack.
• Shell is a wrapper for any existing object to be Stackable without having to extends or create something special. Good for edge cases.
Cherry on the cake, i’ve implemented two more interfaces :
• Progressive which defines a “progress:Number” getter.
• Pausable which is a pause/resume concept.
Both are implemented on the Queue/Sequence/Group objects already (and some other objects, such as Load).
That’s it ! Some misc classes :
• Preloader holds an abstract logic to handle preloaders with Stackable objects.
• Time is only made of static constants.
Examples
• Load uniformity (events, content access) :
var image:Load = new Load('img.png', Load.IMAGE);
image.addEventListener(Event.COMPLETE, oncomplete);
image.load();
function oncomplete(e:Event):void { var bm:Bitmap = e.target.data as Bitmap; }
var xml:Load = new Load('config.xml', Load.TEXT);
xml.addEventListener(Event.COMPLETE, oncomplete);
xml.load();
function oncomplete(e:Event):void { var data:XML = new XML(e.target.data); }
Let’s try to embed Load into our containers :
• Using a sequence to preloads assets of a website :
var config:Load = new Load('config.xml', Load.TEXT);
var locale:Load = new Load('fr_FR.xml', Load.TEXT);
var brands:Load = new Load('brands.png', Load.IMAGE);
var themes:Load = new Load('themes.swf', Load.RSL);
var data:Message = new Message('News.getAll');
var pics:Library = new Library('lib.xml');
var sequence:Sequence = new Sequence();
sequence.addEventListener(Time.STOP, oncomplete);
sequence.stack.push(config, locale, brands, themes, new Call(setup_ui), assets);
sequence.start();
function setup_ui():void { /*do something directly with the RSL*/ }
function oncomplete(e:Event):void { /* display your data */ }
• Using a Group to synchronize ending of custom objects :
var shell1:Shell = new Shell(myCustomObject1, "startFunction", "endingEvent");
var shell2:Shell = new Shell(myCustomObject2, "anotherStartFunction", "diffEndingEvent");
var group:Group = new Group();
group.addEventListener(Time.STOP, oncomplete);
group.stack.push(shell1, shell2);
group.start();
function oncomplete(e:Event):void { /* continue process */ }
• Using a Queue to parallelize some heavy downloads while small are sequenced :
var bigEmbedVideo:Load = new Load('video.swf', Load.SWF);
var queue:Queue = new Queue(2);
queue.addEventListener(Time.STOP, oncomplete);
queue.stack.push(bigEmbedVideo);
for (var i:int = 0; i < 50; i++) { queue.stack.push(new Load(i + '.jpg', Load.IMAGE)); }
queue.start();
function oncomplete(e:Event):void { /* loading done */ }
I think those examples are covering most of the main topics of the package !
As usual, comments are welcome :)