• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

html5 canvas loads image oddly

Hi,
My code works to load an image(s) on a canvas in html.
My question is why does this work .
To me I should not be abkle to trigger an onload function until the image has been assigned.

for (i=0;i<arr1.length;i++){
		images[i] = new Image();
 		images[i].onload = onImgLoad; //how does event trigger if there is nothing to load
 		images[i].src = arr1[i]; // the image to load doesnt happen until next line
	}

Open in new window

0
jagguy
Asked:
jagguy
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
I read it like : << if this event occur on this element >>

onclick : if something/someone click on this
onload : if something/someone load this
0
 
jagguyAuthor Commented:
bit it isnt an  'if', it does load and then assign an image. it reads back to front for me.
0
 
leakim971PluritechnicianCommented:
remove line 4 and wait. wait. wait. :)
line 4 is your trigger if the "source" is valid else you have onerror if error loading this
0
 
jagguyAuthor Commented:
Ok I might close this thread.
let me get this right  that the onload function doesnt trigger until a src is attached so in this sense it is in the right order.
images[i].onload = onImgLoad; //how does event trigger if there is nothing to load
images[i].src = arr1[i]; // the image to load doesnt happen until next line

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now