Scope problem

Hello all,

I am having a problem that I just can’t seem to figure out.

The code below is for a loader that will set the values for some dynamic textboxes as well as a contentpath for a Loader component.

The problem is that if there is no image (file doesn’t exist) then I want to show a “ComingSoon.jpg” file. For some reason, I can’t figure out how to do that. I either get a blank Loader component, or all of my images show the “ComingSoon.jpg” file.

When I do a trace on the “success” variable inside the fileExists.onLoad function it shows me 6 trues and 1 false (which is correct with the data I am passing in). However if I trace immediately after the return like below, I get 7 trues. Any idea as to why? I think it has to do with variable scope, but I am stumped.

trace(fileExists.load(_root["imagePath" + n]))

function dynamicLoad()
{
 for(var n = 1; n <= _root.total; n++)
 {
  // Set x and y coordinates
  setProperty("catch" + n,_x,(_root.contentWidth * n));
  setProperty("catch" + n,_y, 0);
 
  // Set name value
  this["catch" + n].txtName.text = _root["toName" + n];
 
  // Set from name value
  this["catch" + n].txtFromName.text = _root["fromName" + n];
 
  // set recognition value
  this["catch" + n].txtRecognizedFor.text = _root["recognition" + n];
 
  // Set message value
  this["catch" + n].txtMessage.text = _root["message" + n];
  this["catch" + n].txtMessage.setStyle("borderStyle", "none");
  // Check to see if file exists
  fileExists = new LoadVars();
  fileExists.onLoad = function(success)
  {
   //success is true if the file exists, false if it doesn't
   if(success)
   {  
    return true;
   }
   else
   {
    return false;
   }
  }
 
  if(fileExists.load(_root["imagePath" + n]) == true)
  {
   this["catch" + n].imageLoader.contentPath = _root["imagePath" + n];
  }
  else
  {
   this["catch" + n].imageLoader.contentPath = _root["imagePath"] + "ComingSoon.jpg";
  }
 }
}

Thanks in advance for your help!

~ Afflicted