Hi,
I have a simple class that loads 3 movies into empty movie clip containers. This class works as long as I do the 3 loadClip statements outside of the “For Loop”, namely:
mcLoader.loadClip( MOVIE_URL[0], eval(CONTAINER[0]) );
mcLoader.loadClip( MOVIE_URL[1], eval(CONTAINER[1]) );
mcLoader.loadClip( MOVIE_URL[2], eval(CONTAINER[2]) );
But if I include these statements inside the “For Loop”, then it fails, no movies are loaded. I’m baffled! Any help/suggestions would be greatly appreciated.
I have attached the three dummy movies to be loaded. The class can be invoked simply by a “temp = new MovieLoader(_root);” statement.
Thanks!
Ben
// ------- CODE BELOW --------
/*
This class loads 3 movies, just displays them, and stops on the first frame.
*/
class MainLoader {
private var rootMovie: MovieClip;
private var movieCounter: Number = 0;
private static var loadedMovieCounter = 0;
private static var NUM_MOVIES: Number = 3;
private static var MOVIE_URL: Array = new Array(“movie1.swf”, “movie2.swf”, “movie3.swf”);
private static var CONTAINER: Array = new Array(“container1”, “container2”, “container3”);
private var mcLoader: MovieClipLoader;
private var mcLoader_Listener: Object;
function MainLoader(rootMovie: MovieClip) {
this.movieCounter = NUM_MOVIES;
this.rootMovie = rootMovie;
var layerCounter = 50;
mcLoader = new MovieClipLoader();
mcLoader_Listener = new Object();
mcLoader_Listener.ref = this;
mcLoader_Listener.onLoadStart = function(target_mc) {
trace("started loading " + target_mc + ", loadedMovieCounter = " + loadedMovieCounter);
target_mc._visible = false;
loadedMovieCounter++;
};
mcLoader_Listener.onLoadInit = function(target_mc) {
target_mc.gotoAndStop(1);
};
mcLoader_Listener.onLoadComplete = function(target_mc) {
target_mc._visible = true;
trace(“In onLoadComplete: " + target_mc+” finished");
trace("loadedMovieCounter = " + loadedMovieCounter + ", movieCounter = " + this.ref.movieCounter);
if (loadedMovieCounter == this.ref.movieCounter ) {
trace(“ALL MOVIES LOADED into empty movie clips…”);
}
};
mcLoader_Listener.onLoadError = function(target_mc, errorCode) {
trace("ERROR CODE = " + errorCode);
};
/adding the listener/
mcLoader.addListener(mcLoader_Listener);
/create empty movie clips/
//In the for loop, I intend to do a loadClip on the 3 movie clips. But for some
//mysterious reason, it doesn’t work. However, if I simply repeat loadClip the statements 3 times
//as shown below, then it works.
for(var j = 0; j < this.movieCounter; j++) {
this.rootMovie.createEmptyMovieClip( CONTAINER[j], layerCounter++ );
//mcLoader.loadClip( MOVIE_URL[j], eval(CONTAINER[j]) );
}
//This loads 3 movie clips, but I were to include these lines in the loop above, then
//the 3 clips will not be loaded, why???
mcLoader.loadClip( MOVIE_URL[0], eval(CONTAINER[0]) );
mcLoader.loadClip( MOVIE_URL[1], eval(CONTAINER[1]) );
mcLoader.loadClip( MOVIE_URL[2], eval(CONTAINER[2]) );
}
}