I tried searching this forum for “JPEG preloading” but didn’t find the answer to my problem.
Basically my code at the beginning of the movie queries the server for the file names of jpeg files that are to be loaded into sequential frames. The reason is that the user can enter file names into a database and the application plays them back without the user having to do any flash programming.
Currently, my code is using a preloader in each frame along with some additional code to center the picture etc.
This is fine but I need all of the jpegs to load before the movie starts, not when the play head gets to each frame. I can’t have any delay from one frame to the next. Delay in the beginning of the movie is ok.
Can anyone help me with a method to dynamically load these jpegs completely before the movie starts playing?..once loaded they must be available for any frame to call immediately.
You didn’t find an answer for jpg preloading??? :trout:
Anyway, you could put all your jpg’s names in an array in the first frame of your movie, and then load them one by one so that they cache, and play your movie when the last is loaded. Something like that:
stop(); // stop the timeline
myClips = ["jpg1.jpg","jpg2.jpg","jpg3.jpg","jpg4.jpg"];
function loadPic(num){
if (num < myClips.length){
this.createEmptyMovieClip("controller",1000000);
this.createEmptyMovieClip("container",1000001)._visible = 0;
container.loadMovie(myClips[num]);
controller.onEnterFrame = function(){
var l = container.getBytesLoaded();
var t = container.getBytesTotal();
if (l >1 && l >= t) {
delete this.onEnterFrame;
num++;
loadPic(num);
controller.removeMovieClip();
container.removeMovieClip();
}
}
}
}
I’ll give it a try. I figured out something similar except I was using an Empty movie clip that I created on the stage. Your solution is a bit more elegant.
Also, I had to load the jpegs in the second frame because my preloader in the first frame was getting skipped. I was using getBytesLoaded == getBytesTotal. I noticed through trace that this condition was true because both were 0!! For some reason if I put the exact same code in the second frame it worked ok. Trace showed the correct size for getBytesTotal. (just as a point of interest, do you know why this is?)
I see you’ve used getBytesLoaded >1 etc. whcih makes me slap my forehead and say “doh!”
*Originally posted by JDLenner * I see you’ve used getBytesLoaded >1 etc. whcih makes me slap my forehead and say “doh!”
Haha! I had the same reaction when I was shown this trick
Glad you could get it to work.