C
cjl
Hey all:
I have the following (ugly) code:
function preload()
{
if (cr_series.length >1) preloadCR();
if (ct_series.length >1) preloadCT();
if (mr_series.length >1) preloadMR();
if (us_series.length >1) preloadUS();
if (xr_series.length >1) preloadXR();
}
function preloadCR()
{
cr_images = new Array();
for (var loop = 0; loop <= (cr_series.length-2); loop++)
{
cr_images[loop] = new Array();
for (var i = 0;i<4;i++)
{
cr_images[0] = new Image();
cr_images[0].src = "images/cr" + (loop+1) + "_" + (i+1) + ".jpg";
}
}
}
function preloadCT()
{
ct_images = new Array();
for (var loop = 0; loop <= (ct_series.length-2); loop++)
{
ct_images[loop] = new Array();
for (var i = 0;i<4;i++)
{
ct_images[0] = new Image();
ct_images[0].src = "images/ct" + (loop+1) + "_" + (i+1) + ".jpg";
}
}
}
As you can see, the two preload functions (and the others I didn't
paste here) are all but identical, except for the names of the arrays
created and used.
I am a beginner, and having trouble writing a generic function that
could do the same thing, but be called with a paramater:
if (cr_series.length > 1) preload('cr');
I don't know how to take the passed paramated and use it on the 'left'
side of an expression to dynamically create a variable name, etc....
can anyone point me in the right direction?
thanks,
cjl
I have the following (ugly) code:
function preload()
{
if (cr_series.length >1) preloadCR();
if (ct_series.length >1) preloadCT();
if (mr_series.length >1) preloadMR();
if (us_series.length >1) preloadUS();
if (xr_series.length >1) preloadXR();
}
function preloadCR()
{
cr_images = new Array();
for (var loop = 0; loop <= (cr_series.length-2); loop++)
{
cr_images[loop] = new Array();
for (var i = 0;i<4;i++)
{
cr_images[0] = new Image();
cr_images[0].src = "images/cr" + (loop+1) + "_" + (i+1) + ".jpg";
}
}
}
function preloadCT()
{
ct_images = new Array();
for (var loop = 0; loop <= (ct_series.length-2); loop++)
{
ct_images[loop] = new Array();
for (var i = 0;i<4;i++)
{
ct_images[0] = new Image();
ct_images[0].src = "images/ct" + (loop+1) + "_" + (i+1) + ".jpg";
}
}
}
As you can see, the two preload functions (and the others I didn't
paste here) are all but identical, except for the names of the arrays
created and used.
I am a beginner, and having trouble writing a generic function that
could do the same thing, but be called with a paramater:
if (cr_series.length > 1) preload('cr');
I don't know how to take the passed paramated and use it on the 'left'
side of an expression to dynamically create a variable name, etc....
can anyone point me in the right direction?
thanks,
cjl