# Preload code isn't working! Why?

**URL:** https://forum.kirupa.com/t/preload-code-isnt-working-why/111521
**Category:** Uncategorized
**Created:** [May 27, 2004, 8:40pm UTC](https://forum.kirupa.com/t/preload-code-isnt-working-why/111521 "2004-05-27T20:40:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![gragland](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gragland/32/422_2.png) [@gragland](https://forum.kirupa.com/u/gragland)
#### Post date: [May 27, 2004, 8:40pm UTC](https://forum.kirupa.com/t/preload-code-isnt-working-why/111521/1 "2004-05-27T20:40:51Z")

</div>

I am using thise code to load 15 images but its not working. Maybe someone can spot whats wrong. Here is the code in action: [http://s91931107.onlinehome.us/preloader/](http://s91931107.onlinehome.us/preloader/)  
The orange light turns on too fast to have preloaded all 15 images and when i go directly to the path of the image it still has to load (so the preload didnt work). The fifteenth image is the only one that appears instantly when i link directly to it…  
[http://s91931107.onlinehome.us/preloader/weddingsintro4.jpg](http://s91931107.onlinehome.us/preloader/weddingsintro4.jpg)  
[http://s91931107.onlinehome.us/preloader/weddingsintro15.jpg](http://s91931107.onlinehome.us/preloader/weddingsintro15.jpg)  
I put on a trace on the getbytestotal for emptyMC and it said 0, so that may be the problem

Anyway, here ya go:

this.onLoad = function() {  
for (i=1; i\<16; i++) {  
allimages.createEmptyMovieClip(“holder”+i, 1+i);  
emptyMC = “holder”+i;  
section = “weddingsintro”;  
image = section+i+".jpg";  
allimages.loadMovie(image, emptyMC);  
allimages.\_alpha = 0;  
trace (i + “loaded”);

allimages[emptyMC].onEnterFrame = function() {  
if (this.getBytesLoaded() == this.getBytesTotal()) {  
this.loaded = true;  
}  
}

}  
}

this.onEnterFrame = function() {  
var completed = 0;  
for (i=0; i\<16; i++) {  
if (allimages[“holder” + i].loaded == true) {  
completed++;  
trace (i + “completed”);  
}  
}  
if (completed == 15) {  
DONE.play();  
}  
}

---

<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: [May 28, 2004, 12:26pm UTC](https://forum.kirupa.com/t/preload-code-isnt-working-why/111521/2 "2004-05-28T12:26:22Z")

</div>

This question has been answered already. Please refer to one of the 534,187,843,214 corresponding posts 🙂

---

<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: [May 28, 2004, 5:05pm UTC](https://forum.kirupa.com/t/preload-code-isnt-working-why/111521/3 "2004-05-28T17:05:26Z")

</div>

> [@Ilyas le Pom](#):
>
> This question has been answered already. Please refer to one of the 534,187,843,214 corresponding posts 🙂

LOL true,

Umm gragland this bit doesnt make sense

```auto

allimages.createEmptyMovieClip("holder"+i, 1+i);
emptyMC = "holder"+i;
section = "weddingsintro";
image = section+i+".jpg";
allimages.loadMovie(image, emptyMC);

```

Shouldnt it read…

```auto

allimages.createEmptyMovieClip("holder"+i, 1+i);
emptyMC = "holder"+i;
section = "weddingsintro";
image = "section"+i+".jpg";
allimages.loadMovie(image,"holder"+i);

```

Anyway just a thought…TIP: use the AS tags to post your code for readability 😉

---

<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: [May 28, 2004, 8:21pm UTC](https://forum.kirupa.com/t/preload-code-isnt-working-why/111521/4 "2004-05-28T20:21:04Z")

</div>

> [@mindfriction](#):
>
> LOL true,
> 
> Umm gragland this bit doesnt make sense
> 
> ```auto
> 
> allimages.createEmptyMovieClip("holder"+i, 1+i);
> emptyMC = "holder"+i;
> section = "weddingsintro";
> image = section+i+".jpg";
> allimages.loadMovie(image, emptyMC);
> 
> ```
> 
> Shouldnt it read…
> 
> ```auto
> 
> allimages.createEmptyMovieClip("holder"+i, 1+i);
> emptyMC = "holder"+i;
> section = "weddingsintro";
> image = "section"+i+".jpg";
> allimages.loadMovie(image,"holder"+i);
> 
> ```
> 
> Anyway just a thought…TIP: use the AS tags to post your code for readability 😉

But emptyMC = “holder”+i, so it shouldn’t matter if i put emptyMC there.  
And I have done a lot of searching and have yet to find code that preloads dynamically loaded images into dynamically created MC’s.

---

<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: [May 29, 2004, 8:28am UTC](https://forum.kirupa.com/t/preload-code-isnt-working-why/111521/5 "2004-05-29T08:28:51Z")

</div>

> [@gragland](#):
>
> But emptyMC = “holder”+i, so it shouldn’t matter if i put emptyMC there.  
> And I have done a lot of searching and have yet to find code that preloads dynamically loaded images into dynamically created MC’s.

Ahh yeah sorry i didnt see the bit where you stored the var name in emptyMc soz. Hmm there are some components that do this, im in the process of doing something similar myself for a gallery…any gtg. If i have time ill have a look, but hopefully in the meantime someother kind soul from kirupa can help u

---

<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: [May 29, 2004, 7:01pm UTC](https://forum.kirupa.com/t/preload-code-isnt-working-why/111521/6 "2004-05-29T19:01:33Z")

</div>

> [@mindfriction](#):
>
> Ahh yeah sorry i didnt see the bit where you stored the var name in emptyMc soz. Hmm there are some components that do this, im in the process of doing something similar myself for a gallery…any gtg. If i have time ill have a look, but hopefully in the meantime someother kind soul from kirupa can help u

nevermind, i managed to make a preloader that does what i need. thanks
