# Dynamic preloading of multiple images

**URL:** <https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689>\
**Category:** flash\
**Created:** [May 12, 2003, 11:26am UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689 "2003-05-12T11:26:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![oscar\_alexander](https://avatars.discourse-cdn.com/v4/letter/o/e5b9ba/32.png) [@oscar\_alexander](https://forum.kirupa.com/u/oscar_alexander)\
**Post date:** [May 12, 2003, 11:26am UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/1 "2003-05-12T11:26:57Z")

</div>

Hey people. I’m having some serious trouble here. Let me post some code and explain what’s going on:

```auto

Scratch.prototype.loadImages = function() {

	for(i = 1; i <= 6; i++) {
		
		tempObj = _root.mcContainer["mcBox" + i].mcPhotoContainer;
		this.preloadArray*	= tempObj;
		
		tempObj.loadMovie("path/to/image_" + i + ".jpg");
	}
	
	this.preloadImages();
}

Scratch.prototype.preloadImages = function() {

	tempTotal = 0;
	tempLoaded = 0;
	
	for(i = 1; i <= 6; i++) {
		tempObj = this.preloadArray*;
		
		/* This is where poop hits the fan. */
		
		tempTotal += tempObj.getBytesTotal();
		tempLoaded += tempObj.getBytesLoaded();
	}
	
	this.preloaderBytesTotal	= tempTotal;
	this.preloaderBytesLoader	= tempLoaded;
}

```

As you can see, I’m dynamically loading 6 images into 6 boxes (containers). What I’m trying to make is preloader that shows the loading-status of all six images. So I need the totals (total filesize of the 6 images, and the total amount of loaded bytes)… But it doesn’t seem to work this way ☹

Help would be much appreciated.

---

<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 12, 2003, 11:46am UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/2 "2003-05-12T11:46:22Z")

</div>

You seem to be loading all your images into one container which is not possible so your code will be only loading the last image (image\_6.jpg). Try creating 6 different containers and loading each image to a different one, or loading each image to a different level using loadMovieNum.

Hope this helps, let me know if you need any more help

---

<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 12, 2003, 11:53am UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/3 "2003-05-12T11:53:40Z")

</div>

I’m actually loading them into 6 different clips, mcBox1 to mcBox6, which are indeed located within mcContainer. Are you sure that [FONT=courier new]\_root.mcContainer.mcBox1.mcPhotoContainer.getBytesTotal()[/FONT] won’t work?

I’m _really_ confused…

Could you use some code to explain your point please? 😉

---

<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 12, 2003, 12:05pm UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/4 "2003-05-12T12:05:34Z")

</div>

yea, sorry I completely miss-read your post like a \*\*\*\*\*\*\*.

not quite sure exactly what’s going wrong here, what kind of results are you getting?

only thing I can suggest from looking at your code is this:

in preload array you’re storing a series of objects and then using it later to address the relevent image container. I’ve never seen this method before, so am not sure if it works (if you know better then let me know). Rather than storing your objects in an array you could address the ojects like this (in your preload images function):

rather than:

```auto

tempObj = this.preloadArray*;

```

try:

```auto

tempObj = _root.mcContainer["mcBox" + i].mcPhotoContainer;

```

sorry about my first post I’ll stop talking bo\*\*ocks now

---

<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 12, 2003, 12:11pm UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/5 "2003-05-12T12:11:10Z")

</div>

Hehe, that’s quite alright 😉

The storing and addressing of objects in an array works perfectly fine, but what bothers me is that, whenever I trace the getBytesTotal of each individual clip, it outputs 4… So I’m guessing that’s the size of the clip WITHOUT any images in it.

Also, the images _are_ loaded… they’re just not preloaded 😕

---

<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 12, 2003, 12:29pm UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/6 "2003-05-12T12:29:54Z")

</div>

yea as I remember 4 bytes is the exact size of an empty movie clip which would suggest that nothing has yet been loaded.

I had a problem a while back wich was similar to this that turned out to be caused by the fact I was inspecting the empty movie clip too soon after telling it to load a movie. When you tell flash to load a movie flash then has to get the relevent files header that contains information such as filesize. Looks to me that your code is being executed before this has been done. Try running your preload code every frame and see what sort of results you get back.

---

<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 12, 2003, 12:34pm UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/7 "2003-05-12T12:34:51Z")

</div>

Hmm… I noticed one error that you couldn’t have known about: At the bottom of preloadImages, I called the same function again, instead of using setInterval.

Now that I’m using setInterval I seem to get an accurate amount bytes, but only AFTER the entire thing’s been loaded (no inbetweens)… which is strange, because I trace the values within the preloadImages function which should at least be called 5 times during the loading process…

Still baffled ☹

---

<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 12, 2003, 12:41pm UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/8 "2003-05-12T12:41:27Z")

</div>

I take it you’re testing from your local machine?

if you are then the whole image will load when the file header loads so there won’t be any delay between flash recieving the file header and flash recieving the whole file, hence getBytesTotal() goes from returning 4 to showing the right amount AND getBytesLoaded() showing the same number

try uploading your images to a web server and using their url in your movie to test with, its the only way you can test a preloader from a local machine

---

<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 12, 2003, 12:44pm UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/9 "2003-05-12T12:44:11Z")

</div>

Haha, nope 🙂 I’m testing from our LAN… using the Nimbus tool to tackle my bandwidth (taking it down to 56k for testing purposes).

Oh well 🙂

---

<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 12, 2003, 12:47pm UTC](https://forum.kirupa.com/t/dynamic-preloading-of-multiple-images/20689/10 "2003-05-12T12:47:25Z")

</div>

um… …  
… er…  
… …  
… …  
… dang

:trout:
