# If image = null do nothing

**URL:** <https://forum.kirupa.com/t/if-image-null-do-nothing/559737>\
**Category:** Uncategorized\
**Created:** [March 1, 2015, 5:58pm UTC](https://forum.kirupa.com/t/if-image-null-do-nothing/559737 "2015-03-01T17:58:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottiescotsman](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@scottiescotsman](https://forum.kirupa.com/u/scottiescotsman)\
**Post date:** [March 1, 2015, 5:58pm UTC](https://forum.kirupa.com/t/if-image-null-do-nothing/559737/1 "2015-03-01T17:58:34Z")

</div>

This code works apart from when the image = null.

So I have tried a few extra parts of code like lf then … but always get error

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

how would I get it to load a default “0.jpg” if it was = null.

Any help be appreciated

Steven

```
function picLoad():void
{
	trace (trackNumber);
	picLoader = new Loader();
	picLoader.load(new URLRequest(dir + trackNumber + ".jpg"));
	picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
}

/ ********************************************************* /

function onImageLoaded(e:Event):void
{
	var bit:Bitmap = e.target.content;
	if(bit != null)
	{
	bit.smoothing = true;
	bit.x = -(picLoader.width/2);
	bit.y = -(picLoader.height/2);
	art_MC.addChild(picLoader);
	}
}
```

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [March 1, 2015, 7:28pm UTC](https://forum.kirupa.com/t/if-image-null-do-nothing/559737/2 "2015-03-01T19:28:01Z")

</div>

You’re getting an **un** handled IO error event, so handle it. Something like:

```javascript
picLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onImageLoadFailure)

function onImageLoadFailure(e:* = null):void {
    picLoader.load(new URLRequest('0.jpg'))
}

```

---

<div class="post-metadata">

**Author:** ![scottiescotsman](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@scottiescotsman](https://forum.kirupa.com/u/scottiescotsman)\
**Post date:** [March 1, 2015, 9:37pm UTC](https://forum.kirupa.com/t/if-image-null-do-nothing/559737/3 "2015-03-01T21:37:42Z")

</div>

Thanks krilnon 😄

Had to change code a little to remove previous child elements.

```
 / ********! F U N C T I O N S !************************** /

function onImageLoadFailure(e:* = null):void
{
    picLoader.load(new URLRequest(dir + '0.jpg'));
	picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
}

/ ********************************************************* /

function picLoad():void
{
	
	
	picLoader = new Loader();
	picLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onImageLoadFailure);
	picLoader.load(new URLRequest(dir + trackNumber + '.jpg'));
	picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
}

/ ********************************************************* /

function onImageLoaded(e:Event):void
{
	var bit:Bitmap = e.target.content;
	if(bit != null)
	{
	bit.smoothing = true;
	bit.x = -(picLoader.width/2);
	bit.y = -(picLoader.height/2);
	art_MC.removeChildren();
	art_MC.addChild(picLoader);
	}
}
	
/ ********************************************************* /

```

Thanks again from a 48yr old newbie to Xpert.
