PDA

View Full Version : Variable and array looping



Ampulator00
12-20-2004, 11:19 PM
var thisPic = [0, 0, 0, 0, 0];
function chgSlide(change, direction)
{
if(document.images)
{
thisPic[change] += direction;
imgCt = (imageChoice[change].length -1 && altChoice[change].length -1);
if(thisPic[change] > imgCt)
thisPic[change] = 0;
if(thisPic[change] < 0)
thisPic[change] = imgCt;
document.getElementById(slideID[change]).src = imageChoice[change][thisPic[change]];
document.getElementById(slideID[change]).alt = altChoice[change][thisPic[change]];
}
}


The issue is, that I have to put make a new array each time I use the variable "thisPic"; I have been trying to make it loop, but everytime I test it, the browsers I use freezes (Internet Explorer 6.02, Mozilla 1.73, Firefox 1.0). This is a manual slideshow script.

Here's the code that doesn't work:



var thisPic = new Array();
function chgSlide(change, direction)
{

for (change = 0; change < (imageChoice[change].length -1 && altChoice[change].length -1); change++)
{
if(document.images)
{
thisPic[change] += direction;
imgCt = (imageChoice[change].length -1 && altChoice[change].length -1);
if(thisPic[change] > imgCt)
thisPic[change] = 0;
if(thisPic[change] < 0)
thisPic[change] = imgCt;
document.getElementById(slideID[change]).src = imageChoice[change][thisPic[change]];
document.getElementById(slideID[change]).alt = altChoice[change][thisPic[change]];
}
}

}


And here's a separate script that also needs a loop help wit the variable "thisAd":



var cutinID = ["cutin1", "cutin2", "cutin3"],
var thisAd = [-1, -1, -1];

function cycle(x)
{
if(document.getElementById(cutinID[x]).complete)
{
thisAd[x]++;
if(thisAd[x] == time[x])
thisAd[x] = 0;
document.getElementById(cutinID[x]).src = cutinChoice[x][thisAd[x]];
}
setTimeout(function(){cycle(x);} , 2e3);
}