Start a new topic

AR.ImageResource on error

AR.ImageResource on error

Hi,

I want use this code in my html world :

var poiImage = new AR.ImageResource(jsonObject.image, {onError: errorLoadingImage});

But I have a problem with onError function callback which is :

// Called if loading of the image fails
function errorLoadingImage() {            
      document.getElementById("statusElement").innerHTML = 'Impossible to load';// set error message on HUD
}

In this error function, I would prefer to catch the exception and load another picture but I don't know how it's possible ?

Thanks in advance :)
Sorry, I wasn't sign in.

I have another wish. I want to display, the name of the picture on error like this (to debug and solve the problem) :

// Called if loading of the image fails
function errorLoadingImage(errorPicture) {            
      document.getElementById("statusElement").innerHTML = errorPicture;
}

But how to do it ?
hi,

one of the beauties of Javascript is that you get the object the function is called on with "this". Since we call the error function on the specific ImageResource you are able to receive the failed imageresource with this.
 
function errorLoadingImage()
{
var failedImageResource = this;
document.getElementById("statusElement").innerHTML = 'Impossible to load (' + failedImageResource.getUri() + ')';
}
For loading another image  i would simple create a new imageresouce after cleaning up the old one.
failedImageResource.destroy();
var newImageResource = new AR.ImageResource(...
You have to keep in mind that if you already used the imageresouce somewhere that you would need to update it there as well.
Login or Signup to post a comment