The following procedures are part of a class used in reading an image file into a sprite. It works if the URL is correct. But it doesn’t catch errors like a bad url string.
What do I need to change and/or add so that the loadError function is called when needed?
public function readIntoSprite(url:String)
{
this.sprite=new Sprite();
var loader:Loader=new Loader();
var urlRequest:URLRequest=new URLRequest(url);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadSpriteComplete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
this.sprite.addChild(loader);
loader.load(urlRequest);
}
private function loadSpriteComplete(event:Event=null)
{
this.dispatchEvent(new Event(Event.COMPLETE));
}
private function loadError(event:IOErrorEvent)
{
this.dispatchEvent(new Event(Event.CANCEL));
}
Thanks in advance.