I found the problem with the help on someone on another forum, but I know that this solution will be used by others, so I wanted to post the solution here. The problem is that I had used:
Code:
function testExists(imagepath) {
req = getreq();
req.onreadystatechange = imagexists;
req.open("head", imagepath, true);
req.send(null);
}
and it must be:
Code:
function testExists(imagepath) {
req = getreq();
req.onreadystatechange = imagexists;
req.open("head", imagepath, false);
req.send(null);
}
because when it is true (asynchronously), processing continues and req.send(null); does not wait for a response.....so the boolean is not set.
The final correct code is here:
Code:
last part of main function call:
// collapse imagelink array removing missing elements //
for (m=imagetotl-1;m>=3;m--) {
testExists(imagelink[m]);
if(nB) {
imagetotl--;
for (n=m;n<=imagetotl+1;n++) {
imagelink[n]=imagelink[n+1];
}
}
}
// Seed the starting image sequence //
document.pic.src=imagelink[0];
break;
}
}
}
}
function testExists(imagepath) {
req = getreq();
req.onreadystatechange = imagexists;
req.open("head", imagepath, false);
req.send(null);
}
function imagexists() {
if(req.readyState == 4) {
if(req.status == 200)
{
// image exists
nB=false;
}
else
{
// image doesn't exist
nB=true;
}
}
}
function getreq() { // returns false if exists
if(window.ActiveXObject) { // if IE
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
return;
}
}
} else if(window.XMLHttpRequest) { // if Mozilla, Safari, etc.
return new XMLHttpRequest();
}
}
Bookmarks