1

I have an issue in my function and really need your exceptional brain on this.

I need to create a function to stop looking for the next slide and not give me a error message that the asset is not found.

The condition will be created inside the last function below.

Any help will be great.

Thanks in advance.

These are the functions:

var pictureIndex = 1;
var baseUrl = "initialFrames/";
var image_url = undefined;
var timer = setInterval(next, 2500);

var newImage = new Image();
newImage.onload = imageFound;
newImage.onerror = imageNotFound;

function next()
{
  image_url = baseUrl + 'frame_' + pictureIndex + '.jpg';
  tryLoadImage(image_url);
}

function tryLoadImage(url) {
  newImage.src=url;
}

function imageFound() {
  document.getElementById("backInit").src = image_url;
  pictureIndex++;
}

function imageNotFound() {

  // perform some function to stop calling next()
  clearInterval(timer);
}
  • 2
    I dont think your question is clear enough. You call next via `setInterval` and call `clearInterval` on the ID. That will stop next from being called. – Marie Apr 03 '17 at 16:27
  • the code looks correct - what is the error you get? – mplungjan Apr 03 '17 at 16:29
  • I need to stop calling the next() function when it reaches the total number of images found in the assets folder. At the moment it gives me an error saying that can't find the next image that doesn't exist. – Fernando Fas Apr 03 '17 at 16:40
  • for example, I have six images in my folder and error is as follow: GET file:///Users/ferfas/Desktop/1.33_1024x768/initialFrames/frame_7.jpg net::ERR_FILE_NOT_FOUND – Fernando Fas Apr 03 '17 at 16:48
  • Is this what you're doing? http://stackoverflow.com/questions/11144261/javascript-how-to-load-all-images-in-a-folder – CamJohnson26 Apr 03 '17 at 17:01
  • Almost there. Still giving an error as the the next image doesn't exist. GET file:///Users/ferfas/Desktop/1.33_1024x768/initialFrames/fra‌​me_7.jpg net::ERR_FILE_NOT_FOUND – – Fernando Fas Apr 04 '17 at 09:26

0 Answers0