# Jpeg preloading (I did a search!)

**URL:** https://forum.kirupa.com/t/jpeg-preloading-i-did-a-search/22833
**Category:** Uncategorized
**Created:** [June 9, 2003, 12:28pm UTC](https://forum.kirupa.com/t/jpeg-preloading-i-did-a-search/22833 "2003-06-09T12:28:24Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![JDLenner](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@JDLenner](https://forum.kirupa.com/u/JDLenner)
#### Post date: [June 9, 2003, 12:28pm UTC](https://forum.kirupa.com/t/jpeg-preloading-i-did-a-search/22833/1 "2003-06-09T12:28:24Z")

</div>

Hi,

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.

Thanks

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 10, 2003, 3:13pm UTC](https://forum.kirupa.com/t/jpeg-preloading-i-did-a-search/22833/2 "2003-06-10T15:13:59Z")

</div>

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:

```auto
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();
}
}
}
}

```

Something like that…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 10, 2003, 3:58pm UTC](https://forum.kirupa.com/t/jpeg-preloading-i-did-a-search/22833/3 "2003-06-10T15:58:25Z")

</div>

anyway nice to hear “(I did a search!!)” !

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 11, 2003, 2:13am UTC](https://forum.kirupa.com/t/jpeg-preloading-i-did-a-search/22833/4 "2003-06-11T02:13:01Z")

</div>

Thanks Ilyas.

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!”

:thumb:

PS: mlkdesign: you’re welcome!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 11, 2003, 7:03am UTC](https://forum.kirupa.com/t/jpeg-preloading-i-did-a-search/22833/5 "2003-06-11T07:03:09Z")

</div>

Hi Ilyas,

It works fine. I had to do the recursion after removing the clips to get all the pics to load.

Thanks

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 11, 2003, 4:26pm UTC](https://forum.kirupa.com/t/jpeg-preloading-i-did-a-search/22833/6 "2003-06-11T16:26:09Z")

</div>

> \*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.
