# Loading External Images but need a way to loop that allow the load- can anyone help?

**URL:** https://forum.kirupa.com/t/loading-external-images-but-need-a-way-to-loop-that-allow-the-load-can-anyone-help/327470
**Category:** flash
**Created:** [March 2, 2012, 9:56pm UTC](https://forum.kirupa.com/t/loading-external-images-but-need-a-way-to-loop-that-allow-the-load-can-anyone-help/327470 "2012-03-02T21:56:13Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![HumanEvent](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@HumanEvent](https://forum.kirupa.com/u/HumanEvent)
#### Post date: [March 2, 2012, 9:56pm UTC](https://forum.kirupa.com/t/loading-external-images-but-need-a-way-to-loop-that-allow-the-load-can-anyone-help/327470/1 "2012-03-02T21:56:13Z")

</div>

Hi,

So I 'm checking to see if an image file exist but I don’t think the code checks but the last iteration in the loop. Here’s my code:

var i = 1;  
var j;  
var loader:URLLoader = new URLLoader();  
var myArr:Array = new Array();

loader.addEventListener(IOErrorEvent.IO\_ERROR, imgLoadErrorMethod);

var request:URLRequest = new URLRequest(“images/birds” + i + “.jpg”);

for (i = 1; i \<= 8; i++)  
{  
request = new URLRequest(“images/birds” + i + “.jpg”);  
loader.load(request);  
trace ("i: " + i)  
}

function imgLoadErrorMethod(event:IOErrorEvent):void {  
trace("ioErrorHandler: ");  
j = i - 1 ;  
trace(“images/birds” + j + “.jpg. Does not exist”)  
}

THIS IS WHAT IT OUTPUTS:

i: 1  
i: 2  
i: 3  
i: 4  
i: 5  
i: 6  
i: 7  
i: 8  
ioErrorHandler:  
images/birds8.jpg. Does not exist

I only have 7 images. If I change the 8 in the for loop to 9  
THIS IS WHAT IT OUTPUTS:

i: 1  
i: 2  
i: 3  
i: 4  
i: 5  
i: 6  
i: 7  
i: 8  
i: 9  
ioErrorHandler:  
images/birds9.jpg. Does not exist

I was expecting a both  
ioErrorHandler:  
images/birds8.jpg. Does not exist  
ioErrorHandler:  
images/birds9.jpg. Does not exist

Can someone help me fix this or if you know a better way to check if an image file exist could you let me know.
