# External loading function & looping

**URL:** <https://forum.kirupa.com/t/external-loading-function-looping/182543>\
**Category:** Uncategorized\
**Created:** [March 19, 2006, 6:21am UTC](https://forum.kirupa.com/t/external-loading-function-looping/182543 "2006-03-19T06:21:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![plankguy](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@plankguy](https://forum.kirupa.com/u/plankguy)\
**Post date:** [March 19, 2006, 6:21am UTC](https://forum.kirupa.com/t/external-loading-function-looping/182543/1 "2006-03-19T06:21:49Z")

</div>

Okay, here it is…

I am loading external jpg’s whos names I have stored in an array. I have an loadProject function that is called when the user clicks a button. The attach image function fades the last image out then once it is, calls my preloadImage function. I then want to test for if the image is preloaded so that the new image can fade in…Thing is that it only wants to call the preload function and move on…(i think). So how can I loop to test if loaded and once it is, move on to the new image fade in?! I’ve with while but i get the big 'ol crash…Any ideas!!!

loadImage function:

```auto
function loadProject() {
 onEnterFrame = function () {
  _parent.masterHolder.cover.endAlpha = 100;
  if (_parent.masterHolder.cover._alpha == 100) {
   loadMovie(projPhoto, _parent.masterHolder.holder);
   preloadImage();
   do {
   trace("Loading....");
   } while (!success);
    trace("Fade new image in!");
  }
 };
}

```

preloadImage function:

```auto
 
function preloadImage(success) {
 onEnterFrame = function () {
  loaded = _parent.masterHolder.holder.getBytesLoaded();
  filesize = _parent.masterHolder.holder.getBytesTotal();
  percent = (loaded/filesize)*100;
  if (isNaN(percent)) {
   percent = 0;
  }
  _parent.masterHolder.percent = Math.ceil(percent)+"%";
  _parent.masterHolder.preloader.preload_bar._xscale += (percent-_parent.masterHolder.preloader.preload_bar._xscale)/3;
  if (_parent.masterHolder.preloader.preload_bar._xscale>=95 && percent == 100) {
   trace("LOADED 100%");
   delete this.onEnterFrame;
   _parent.masterHolder.preloader.preload_bar._xscale = 1;
   _parent.masterHolder.percent = "";
  }
 };
}

```
