# Statement behavior different inside Loop

**URL:** <https://forum.kirupa.com/t/statement-behavior-different-inside-loop/87270>\
**Category:** flash\
**Created:** [April 19, 2005, 7:17pm UTC](https://forum.kirupa.com/t/statement-behavior-different-inside-loop/87270 "2005-04-19T19:17:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![educasia](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@educasia](https://forum.kirupa.com/u/educasia)\
**Post date:** [April 19, 2005, 7:17pm UTC](https://forum.kirupa.com/t/statement-behavior-different-inside-loop/87270/1 "2005-04-19T19:17:47Z")

</div>

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](https://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]) );  
}  
}
