I am working on a image preloader
aImages=[“1.jpg”,“2.jpg”,“3.jpg”,“4.jpg”];
for (var i:Number=0; i<aImages.length;i++){
var temp2:MovieClip=this.createEmptyMovieClip(“temp”+i, this.getNextHighestDepth());
preloadImage(temp2,aImages*);
trace(temp2);
}
function preloadImage(temp2:MovieClip,path:String){
temp2.loadMovie(path);
this.onEnterFrame = function() {
var total = temp2.getBytesTotal();
var loaded = temp2.getBytesLoaded();
percent = Math.round(loaded/total*100);
if(percent==100){
// trace(loaded);
delete this.onEnterFrame;
}
}}
The code runs fine by itself, but when i plug it in the other function.
Instead of getting all the image display on the stage, it only manage to display the last image, as if i=3 and only display 4.jpg. The trace can output 0,1,2,3 for i.
But when comes to preloading it on the stage, it seem like it only called the function when it finished looping, but not during the loop, any ideas?
Felix