title: javascript preload image array keep requesting image
body: <p>I have a preload function that makes an array with the source of some images.</p>
  
  <pre><code>function preload() {
    for (var n = 0; n &lt; urls.length; n++) {
        images[n] = new Image;
        images[n].onload = updateCurrenttype();
        images[n].src = urls[n];
        console.log('urlsPreload[n]: '+urls[n]);
    }
  }
  
  function updateCurrenttype() {
  currenttype = 1;
   }
  </code></pre>
  
  <p>The update current type function, should be like a flag to check if the image should be requested or not. But obviously is not working as intended :D</p>
  
  <p>Then I have a show function to display the images, but for some reason which I can't see, the images keep been requested again and again. Instead of using the ones in the preload array.</p>
  
  <pre><code>function showimage() {
  if (currenttype != 0) {
      imageitem.src = images[currentindex].src;
  }
      console.log('urls[ci]:'+images[currentindex].src);
  }
  </code></pre>
  
  <p>These images are an animation, so instead of downloading the images again and again I would like them to be reuse. </p>
  
  <p>Any suggestion how to achieve this?</p>