Click to See Complete Forum and Search --> : why do i get bumped out of my code?


zubora
12-28-2002, 07:20 AM
I've been working with image swapping, and while my code works correctly the first time, on the second run, it terminates abruptly before swapping the actual image (which I verified using alert messages). I call my code from an onClick via an image within the page itself. Could someone please take a look and tell me what I'm doing wrong? It's driving me nuts! :eek:

function showNewPic(p){
//load selected Array if not already loaded
if(currentpic == 0){
var images = new Array(pickArray.length-1);
for (var i=0; i<(pickArray.length); i++) {
images[i] = new Image();
images[i].src = "images/portfolio/" + pickArray[i] + ".gif";}
}

if(currentpic + p > pickArray.length-1){
currentpic = 0; }
else if(currentpic + p < 0){ currentpic = pickArray.length;}
else{currentpic = currentpic + p;}

document.pfolio.src = images[currentpic].src;
}
</script>

zubora
12-28-2002, 09:53 AM
I figured it out:
It was because the image array was undefined the second time I tried to call it - a rookie mistake I suppose. I separated out the image loading from my function and created a new array name and now the code works. Hooray!
And thanks anyway :)

zubora
12-28-2002, 10:25 AM
Hi Dave,
Actually, I had forgotten to turn on error message reporting after I had reinstalled my OS. *blush*
But now I've got it and hopefully I won't make this same mistake again. Thanks for the tip and I'll try to provide all the information next time.
Cheers! :)