# Help! preloading a random background

**URL:** https://forum.kirupa.com/t/help-preloading-a-random-background/117127
**Category:** Uncategorized
**Created:** [July 24, 2004, 4:50pm UTC](https://forum.kirupa.com/t/help-preloading-a-random-background/117127 "2004-07-24T16:50:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![juicestain](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@juicestain](https://forum.kirupa.com/u/juicestain)
#### Post date: [July 24, 2004, 4:50pm UTC](https://forum.kirupa.com/t/help-preloading-a-random-background/117127/1 "2004-07-24T16:50:56Z")

</div>

I can’t tell you how long I’ve slaved over this question. I would ultimately like to load a random background, but first I’m just trying to preload a script-defined background. This is the coding I’m at right now and it doesn’t work at all; it just sits with an empty load bar and “NaN% loaded” as the text. Any help you guys could give me would be VERY MUCH appreciated. Thanks in advance!

Justin

Here’s the script–

stop();  
//pic folder name  
folder = “pics”;

//create Holder and place him  
this.createEmptyMovieClip(“image”, 1);  
image.\_x = 0;  
image.\_y = 0;

//load the content  
image.loadMovie(folder + “/background.jpg”);

//declare and launch preload  
var content = image;  
loadNow(content);

function loadNow(content) {  
//Turn on and initialize the preloader  
\_root.loadBar.\_xscale = 0;  
\_root.loadText = “0% loaded”;  
//Set an interval to update the loading progress  
loadInterval = setInterval(checkProgress, 10, content);  
}

function checkProgress(content) {  
//Set all variables to default  
var contentSize = 0;  
var downloaded = 0;  
var percntLoaded = 0;  
//Get total and loaded bytes  
contentSize = content.getBytesTotal();  
downloaded = content.getBytesLoaded();  
percentLoaded = Math.ceil(downloaded / contentSize \* 100);

```
//Update the preloader display
_root.loadText = percentLoaded + "% loaded";
_root.loadBar._xscale = percentLoaded;
updateAfterEvent();

//Is everything loaded?
if (downloaded == contentSize && contentSize &gt; 0) {
	clearInterval(loadInterval);
}

```

}
