# Check if image exists?

**URL:** <https://forum.kirupa.com/t/check-if-image-exists/183588>\
**Category:** Uncategorized\
**Created:** [March 28, 2006, 4:50pm UTC](https://forum.kirupa.com/t/check-if-image-exists/183588 "2006-03-28T16:50:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pram310](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@pram310](https://forum.kirupa.com/u/pram310)\
**Post date:** [March 28, 2006, 4:50pm UTC](https://forum.kirupa.com/t/check-if-image-exists/183588/1 "2006-03-28T16:50:44Z")

</div>

Hi all

I’ve been trying to load a different image if an image doesn’t exist. How I go about it is: I using the loadVars methods, and defined an onLoad event to fire. On successful file load, it should display the associated image, and if the load fails, it should load “noImage.gif”. I have pictures p1.gif…p6.gif and the rest are missing.

```auto

for (i=0; i<10; i++){
s = "p" + i + ".gif";
fileExists=new LoadVars();
fileExists._parent=this;
fileExists.onLoad=function(success)
{
//success is true if the file exists, false if it doesnt
    if(success)
    {
        //the file exists
//nm is an existing movie container
nm.loadMovie(sImage); //and load our .swf file into it
    }
else
nm.loadMovie('noImage.gif');
}
fileExists.load(sImage); //initiate the test
}

```

My problem is that file load is always a success, even when the file doesn’t exist, so the else part never fires. I just see a blank where the image should be. If the image exists, it shows up as expected.

TIA

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 28, 2006, 4:59pm UTC](https://forum.kirupa.com/t/check-if-image-exists/183588/2 "2006-03-28T16:59:43Z")

</div>

Change this line:

```auto
fileExists.onLoad=function(success)

```

to

```auto
fileExists.onLoad = function(success:Boolean)

```

If you don’t do that, it’s just a variable with a string, then it’s always true because it has a value. This way it is actually treated as a true or false statement(Boolean)

---

<div class="post-metadata">

**Author:** ![pram310](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@pram310](https://forum.kirupa.com/u/pram310)\
**Post date:** [March 28, 2006, 5:33pm UTC](https://forum.kirupa.com/t/check-if-image-exists/183588/3 "2006-03-28T17:33:04Z")

</div>

Thank you! you are a genius 😃
