Hello,
I am making an application where there is the need to load a lot of images.
To avoid loading them all at the same time, Ive created a singleton named
SequentialLoader that loads one at a time. The behavior of this class is
simple: it has an array of moviesToLoad (url, target, callback function),
and it starts loading the first movie on the array using the moviecliploader
class and setting its state to busy. When loading finishes, and onLoadInit
is called, busy state is set to false, and SequentialLoader starts loading
the next movie. And so on
The class is working fine, except if the user decides to change to another
section on the application during the loading process. When section changes,
the previous section is removed using .removeMovieClip, and since target_mc
was inside the removed movieclip, it is also deleted. When image arrives
onLoadInit is not called, and SequentialLoader hangs, because busy state is
never set to false.
I am stuck with this problem, and havent found a way to solve it.
Any suggestions would be much appreciated.
Below, is the code of my class:
import pt.webfuel.utils.MovieToLoad;
class pt.webfuel.utils.SequentialLoader {
var moviestoload:Array;
var cur_movie:Object;
var busy:Boolean=false;
static var inst:SequentialLoader;
////////////////////////////////////////////////////////////////////////////
// SequentialLoader()
////////////////////////////////////////////////////////////////////////////
function SequentialLoader() {
moviestoload= new Array();
}
////////////////////////////////////////////////////////////////////////////
// addMovie()
////////////////////////////////////////////////////////////////////////////
function addMovie(movie:MovieToLoad, highPriority:Boolean) {
if (movie.url!=null and movie.holder!=null) {
if (highPriority)
moviestoload.unshift(movie);
else
moviestoload.push(movie);
start();
}
}
////////////////////////////////////////////////////////////////////////////
// start()
////////////////////////////////////////////////////////////////////////////
function start() {
if (!busy) {
busy=true;
if(moviestoload.length==0)
busy=false;
cur_movie=moviestoload.shift();
if (cur_movie!=null) {
if (cur_movie.holder!=null) {
var mcl:MovieClipLoader = new
MovieClipLoader();
mcl.addListener(this);
mcl.loadClip(cur_movie.url,
cur_movie.holder);
} else start()
}
} else {
//trace("I was supposed to start, but I was busy");
}
}
////////////////////////////////////////////////////////////////////////////
// onLoadError()
////////////////////////////////////////////////////////////////////////////
private function onLoadError(target_mc:MovieClip) {
busy=false;
start();
}
////////////////////////////////////////////////////////////////////////////
// onLoadInit()
////////////////////////////////////////////////////////////////////////////
private function onLoadInit(target_mc:MovieClip) {
cur_movie.func_to_call(target_mc);
busy=false;
start();
}
////////////////////////////////////////////////////////////////////////////
// getInstance()
////////////////////////////////////////////////////////////////////////////
public static function getInstance ():SequentialLoader
{
if ( inst == null ) {
inst = new SequentialLoader();
return inst;
} else {
return inst;
}
}
}
Thanks,
João Saleiro
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org