/***************************************************
Loading stack
(queue)
Makes it easy
to load a bunch of external .swf into
targets in sequence.
originally
made by Martin Smestad Hansen, www.visual-funk.com
(c0rgan @ #flashhelp, EFnet. Thanks to Squee-D for better
and shorter code)
Use as you
please. If you make any improvements, I'd be
happy to see it. (Could be nice to not have to add code
to the placeholder mc)
--------------------------------------------------
HOW TO USE:
- include this file in your _root-timeline.
attach the following code to the target mcs
you are loading your swfs into:
------------------------------------------------------------------
onClipEvent(data){
if (this.getBytesLoaded() == this.getBytesTotal()) {
_root.stackLoader.loadNext();
}
}
------------------------------------------------------------------
First, you
need to create a stackLoader-object, like this:
stackLoader = new StackLoader();
To add files
for loading:
stackLoader.addFile("myExternalFile.swf, "targetPlacholderMC");
To start loading
all files in the stackloader:
stackLoader.loadNext();
Comments:
------------------------------------------------------------------
if you need to know when all clips are loaded, change the code
on your placeholderclip to do something based on what loadNext
returns
it will return 0 if there's nothing more to load.
if ( !_root.stackLoader.loadNext()
) {goDoSomething();}
------------------------------------------------------------------
This is a FIFO-stack, or queue (first in, first out). It can easily
be turned into a LIFO (last in, first out) by changing one line
of code
in the loadNext() function;
this.currentMovie
= this.movieArray.shift(); to
this.currentMovie = this.movieArray.pop();
------------------------------------------------------------------
*******************************************************/
//Class StackLoader
function StackLoader
() {
//creates the array that will contain our loading queue
this.movieArray = new Array();
}
//StackLoader methods
StackLoader.prototype.addFile
= function(filename, loadTarget) {
//adds another movie to the end of the array.
this.movieArray.push( {
filename:filename, loadTarget:loadTarget
})
};
StackLoader.prototype.clearStack
= function() {
//clears the array, so no more loading will be started.
this.movieArray.length = 0;
};
StackLoader.prototype.loadNext
= function() {
if (this.movieArray.length > 0) {
//if there is anything in the array, delete the first element,
//and load it into it's target.
this.currentMovie = this.movieArray.shift();
loadMovie (this.currentMovie.filename, this.currentMovie.loadTarget);
return 1;
} else {
//array is empty. Nothing more to load, so return zero
return 0;
}
};
[
back ]
|