shashgo
10-19-2002, 10:18 PM
The following scipt works to some extent. I have a total of 134 images that I want the script to try and load. Some of these images are bogus and will not load or they might be non existant. So what I have done is store the number of successfully loaded images in variable numImages and ignore the ones that are in error.
The script works well for an image fcount of less than 17 where the value of numImages increments to 16 (17 minus 1, which is okay). The script does not increment the value of numImages correctly if the image count is more than 17. I put a confirm statement at the end of the loop that tries to load the images, and this caused a necessary delay needed so that each of the images could be processed so numImages could increment properly. When I took out the confirm, the script started acting up again.
So,the question is: can I somehow introduce a delay in the script so that it works fine, an if so, how would I know for how long?
The script is:
--------------------------------
<html>
<head>
<title>Nisha</title>
<script language="javascript">
<!--
var numImages=0;
var imgArray=new Array();
var imgNum;
var Number=134;
var Current=0;
var pause;
function loadEm()
{
for (i=1;i<=Number;i++)
{
pic=new Image();
pic.onerror=function(){document.frm.disp.value="Picture "+i+" not loaded";};
pic.onload=function()
{
imgArray[numImages]=new Image();
imgArray[numImages].src=this.src;
document.frm.disp.value="Picture "+i+" loaded as imgArr["+numImages+"]";
numImages++;
}
pic.src=i+".jpg";
}
}
function inter()
{
pause=prompt("Number of images loaded"+numImages+"\nEnter interval for slideshow","2000");
disp();
}
function disp()
{
document.frm.disp.value="Picture "+Current;
document.nisha.src=imgArray[Current].src;
if (Current>0) Current--; else Current=numImages-1;
setTimeout("disp()",pause);
}
-->
</script>
</head>
<body onload="loadEm()">
<form name="frm"><input type="text" name="disp" size="40"></form><img src="" name="nisha" align="left">
<a href="javascript:inter()">Start slideshow"</a>
</body>
</html>
The script works well for an image fcount of less than 17 where the value of numImages increments to 16 (17 minus 1, which is okay). The script does not increment the value of numImages correctly if the image count is more than 17. I put a confirm statement at the end of the loop that tries to load the images, and this caused a necessary delay needed so that each of the images could be processed so numImages could increment properly. When I took out the confirm, the script started acting up again.
So,the question is: can I somehow introduce a delay in the script so that it works fine, an if so, how would I know for how long?
The script is:
--------------------------------
<html>
<head>
<title>Nisha</title>
<script language="javascript">
<!--
var numImages=0;
var imgArray=new Array();
var imgNum;
var Number=134;
var Current=0;
var pause;
function loadEm()
{
for (i=1;i<=Number;i++)
{
pic=new Image();
pic.onerror=function(){document.frm.disp.value="Picture "+i+" not loaded";};
pic.onload=function()
{
imgArray[numImages]=new Image();
imgArray[numImages].src=this.src;
document.frm.disp.value="Picture "+i+" loaded as imgArr["+numImages+"]";
numImages++;
}
pic.src=i+".jpg";
}
}
function inter()
{
pause=prompt("Number of images loaded"+numImages+"\nEnter interval for slideshow","2000");
disp();
}
function disp()
{
document.frm.disp.value="Picture "+Current;
document.nisha.src=imgArray[Current].src;
if (Current>0) Current--; else Current=numImages-1;
setTimeout("disp()",pause);
}
-->
</script>
</head>
<body onload="loadEm()">
<form name="frm"><input type="text" name="disp" size="40"></form><img src="" name="nisha" align="left">
<a href="javascript:inter()">Start slideshow"</a>
</body>
</html>