# Preloader keeps resetting/sticks when trying to load external images

**URL:** https://forum.kirupa.com/t/preloader-keeps-resetting-sticks-when-trying-to-load-external-images/228154
**Category:** flash
**Created:** [June 5, 2007, 7:34pm UTC](https://forum.kirupa.com/t/preloader-keeps-resetting-sticks-when-trying-to-load-external-images/228154 "2007-06-05T19:34:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ajmedway](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ajmedway/32/3704_2.png) [@ajmedway](https://forum.kirupa.com/u/ajmedway)
#### Post date: [June 5, 2007, 7:34pm UTC](https://forum.kirupa.com/t/preloader-keeps-resetting-sticks-when-trying-to-load-external-images/228154/1 "2007-06-05T19:34:59Z")

</div>

Hi to all,

**THE PROJECT:**  
I’m making a portfolio site in FLASH MX 2004 that displays images from an external folder, indexed in an array.

I’ve set it up so that a user clicks on a button to get a different image from an array - the images are loaded externally - the alpha value for the current image is set to zero and then the border around the image shrinks to 80x50.

Then the new image is preloaded (using a simple bar in a movie clip to graphically display this in the 80x50 border). Then the width and height of the image are read and the border is dynamically sized to fit around the image and the alpha value of that is set to 100 to show it.

**THE PROBLEM:**  
An if statement is used so that when the border shrinks to be exactly 80x50, the call to"photo\_mc.loadPhoto(image\*);" is triggered, where the selected image is preloaded and the details of its width and height are retrieved to send to another function, which sizes the border and sets alpha of image to 100.

But, as the condition is always true (i.e. border remains @ 80x50 during preload), the preloader freezes, as the call to send the image to the loadPhoto function is perpetually made. When running the finished flash movie (with photos loaded locally) on my computer, obviously there is no preloader and it all works as planned. Only when you run it online this happens…

Go to

[www.aidybrooks.co.uk](http://www.aidybrooks.co.uk)

to see what I mean. (if you look on mozilla firefox you can actually see the function getting called perpetually - the preloader keeps resetting to 1pixel, but the photos eventually load!)

\*\*PLEASE HELP ME GET ROUND THIS! \*\*im sure its probably quite simple…

**HERE’S THE RELEVANT ACTIONSCRIPT:**

INFO\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

instance names:

photo\_mc = the empty movie clip into which the images are loaded  
border = the border that fits around the image displayed in photo\_mc  
pBar = preloader bar movie clip

* * *

-----//This function is called whenever a button is clicked to change the photo displayed in photo\_mc

MovieClip.prototype.changePhoto = function() {  
photo\_mc.\_alpha = 0;  
var dw = 80;  
var dh = 50;  
border.desize(dw, dh);  
};

-----//This function shrinks the border to 80\*50 pixels, into which the preloader for the image fits nicely

MovieClip.prototype.desize = function(dw, dh) {  
var dspeed = 3;  
this.onEnterFrame = function() {  
this.\_width += (dw-this.\_width)/dspeed;  
this.\_height += (dh-this.\_height)/dspeed;  
if (Math.abs(this.\_width-dw)\<1 && Math.abs(this.\_height-dh)\<1) {  
//if 80x50, execute following code…  
photo\_mc.loadPhoto(image\*); //send image from array to load into photo\_mc  
}  
};  
};

-----//This function runs the preloader once the “photo\_mc” movie clip has loaded  
MovieClip.prototype.loadPhoto = function(photo) {  
this.loadMovie(photo);  
pBar.\_width = 1; //reset preloader bar to 1 pixel before displaying the preloader  
\_level0.onEnterFrame = function() {  
var total = Math.round(photo\_mc.getBytesTotal()/1024);  
var loaded = Math.round(photo\_mc.getBytesLoaded()/1024);  
pBar.\_visible = true;  
//PRELOADER BAR WIDTH AS % OF LOADED  
pBar.\_width = (loaded/total)\*40;  
//100% = 40 pixels  
if (total != 0 && loaded\>=total) {  
pBar.\_visible = false;  
var w = photo\_mc.\_width+space;  
var h = photo\_mc.\_height+space;  
border.resize(w, h);  
delete this.onEnterFrame;  
}  
};  
};

-----//After this, the border is resized to fit around the photo, and the photo\_mc alpha value is set to 100 to show the image
