title: Image Preloading in Canvas
body: <p>I'm drawing an Image on the canvas using the drawImage function. This is how Im setting the src property of the image:</p>
  
  <blockquote>
    <p>var img = new Image();   // Create new Image object<br>
    img.src = 'test.php?filename=myfile.jpg'</p>
  </blockquote>
  
  <p>and then</p>
  
  <blockquote>
    <p>oCanvas.width = 600;
      oCanvas.height = 400;
      oContext.drawImage(img, 0, 0, 600, 400);</p>
  </blockquote>
  
  <p>The problem is that if the src isn't set then I get the foll error:"<strong>uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMCanvasRenderingContext2D.drawImage]"</strong> . I know I get this error coz the image hasnt finished loading. I added an alert just before the call to drawImage function to let the image finish loading and it seems to work. But it's a pain in the neck. How do I check if the image has finished loading? BTW I have to set the src property by calling a php file.</p>