Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preload in a loop?

Status
Not open for further replies.

davv

Programmer
Apr 18, 2001
10
SE
Hello all programmers!

I want to preload 60 images. There are 20 jpegs with 3 variations each. The images are named ovn1_niv1, ovn1_niv2, ovn1_niv3, ovn2_niv1... So instead of writing almost the same lines 60 times I want to preoload them with two loops. I hoped that this would work but it doesn’t. Anyone have any ideas?

for (i=1; i<=20; i++){
for (j=1; j<=3; j++){
eval(&quot;var ovn&quot;+i+&quot;niv&quot;+j+&quot; = new Image()&quot;);
eval(&quot;ovn&quot;+i+&quot;niv&quot;+j+&quot;.src&quot;) = eval(&quot;ovn&quot;+i+ &quot;/niv&quot;+j+
&quot;/ovn&quot;+i+&quot;_niv&quot;+j+&quot;.jpg&quot;);
}
}

 
this have to be working:

for (i=1; i<=20; i++){
for (j=1; j<=3; j++){
var tmp = eval(&quot;ovn&quot;+i+&quot;niv&quot;+j+&quot; = new Image()&quot;);
tmp.src = &quot;ovn&quot;+i+ &quot;/niv&quot;+j+&quot;/ovn&quot;+i+&quot;_niv&quot;+j+&quot;.jpg&quot;
}
}

why did you used eval() for src?
src is just a string with path;
am i missing something? Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top