Click to See Complete Forum and Search --> : Parameter Issue???


NetworkRanger
06-03-2003, 09:37 AM
I have been struggling with this for some time.
If someone could look at it, they will probably see something I am missing.

I get an error message saying "images[] is null or not an object".
The message is coming from the setcurrent() function call from the onClick event handler.

Here is the code (all this stuff is in the head of the doc):

// Set up array of images that can be shown.
// Define image array
var x;
var y;
var z;
var images = new Array(1);
for (x=0; x < 1; x++)
{
images[x] = new Array(3);
for (y=0; y < 3; y++)
{
images[x][y] = new Array(28);
for (z=0; z < 28; z++)
{
images[x][y][z] = "";
}
}
}
// Job Index
var jobindex = 1;

// Date Index
var dateindex = 1;

// File Index
var fileindex = 1;

images[1][1][1] ="27917\/05262003\/MVC-001S.JPG";
images[1][1][2] ="27917\/05262003\/MVC-001S1.JPG";
images[1][1][3] ="27917\/05262003\/MVC-002S.JPG";
images[1][1][4] ="27917\/05262003\/MVC-002S1.JPG";
images[1][1][5] ="27917\/05262003\/MVC-003S.JPG";
images[1][1][6] ="27917\/05262003\/MVC-003S1.JPG";
images[1][1][7] ="27917\/05262003\/MVC-004S.JPG";
images[1][1][8] ="27917\/05262003\/MVC-004S1.JPG";
images[1][1][9] ="27917\/05262003\/MVC-005S.JPG";
images[1][1][10] ="27917\/05262003\/MVC-005S1.JPG";
images[1][1][11] ="27917\/05262003\/MVC-006S.JPG";
images[1][1][12] ="27917\/05262003\/MVC-006S1.JPG";
images[1][1][13] ="27917\/05262003\/MVC-007S.JPG";
images[1][1][14] ="27917\/05262003\/MVC-008S.JPG";
images[1][1][15] ="27917\/05262003\/MVC-009S.JPG";
images[1][1][16] ="27917\/05262003\/MVC-010S.JPG";
images[1][1][17] ="27917\/05262003\/MVC-011S.JPG";
images[1][1][18] ="27917\/05262003\/MVC-012S.JPG";
images[1][1][19] ="27917\/05262003\/MVC-013S.JPG";
images[1][1][20] ="27917\/05262003\/MVC-014S.JPG";
images[1][1][21] ="27917\/05262003\/MVC-015S.JPG";
images[1][1][22] ="27917\/05262003\/MVC-016S.JPG";
images[1][1][23] ="27917\/05262003\/MVC-017S.JPG";
images[1][1][24] ="27917\/05262003\/MVC-018S.JPG";
images[1][1][25] ="27917\/05262003\/MVC-019S.JPG";
images[1][1][26] ="27917\/05262003\/MVC-020S.JPG";
images[1][1][27] ="27917\/05262003\/MVC-021S.JPG";
images[1][1][28] ="27917\/05262003\/MVC-022S.JPG";
images[1][1][0] ="28";
images[1][2][1] ="27917\/05262003_1\/MVC-001S.JPG";
images[1][2][2] ="27917\/05262003_1\/MVC-001S1.JPG";
images[1][2][3] ="27917\/05262003_1\/MVC-002S.JPG";
images[1][2][4] ="27917\/05262003_1\/MVC-002S1.JPG";
images[1][2][5] ="27917\/05262003_1\/MVC-003S.JPG";
images[1][2][6] ="27917\/05262003_1\/MVC-003S1.JPG";
images[1][2][7] ="27917\/05262003_1\/MVC-004S.JPG";
images[1][2][8] ="27917\/05262003_1\/MVC-004S1.JPG";
images[1][2][9] ="27917\/05262003_1\/MVC-005S.JPG";
images[1][2][10] ="27917\/05262003_1\/MVC-005S1.JPG";
images[1][2][11] ="27917\/05262003_1\/MVC-006S.JPG";
images[1][2][12] ="27917\/05262003_1\/MVC-006S1.JPG";
images[1][2][13] ="27917\/05262003_1\/MVC-007S.JPG";
images[1][2][14] ="27917\/05262003_1\/MVC-008S.JPG";
images[1][2][15] ="27917\/05262003_1\/MVC-009S.JPG";
images[1][2][16] ="27917\/05262003_1\/MVC-010S.JPG";
images[1][2][17] ="27917\/05262003_1\/MVC-011S.JPG";
images[1][2][18] ="27917\/05262003_1\/MVC-012S.JPG";
images[1][2][19] ="27917\/05262003_1\/MVC-013S.JPG";
images[1][2][20] ="27917\/05262003_1\/MVC-014S.JPG";
images[1][2][21] ="27917\/05262003_1\/MVC-015S.JPG";
images[1][2][22] ="27917\/05262003_1\/MVC-016S.JPG";
images[1][2][23] ="27917\/05262003_1\/MVC-017S.JPG";
images[1][2][24] ="27917\/05262003_1\/MVC-018S.JPG";
images[1][2][25] ="27917\/05262003_1\/MVC-019S.JPG";
images[1][2][26] ="27917\/05262003_1\/MVC-020S.JPG";
images[1][2][27] ="27917\/05262003_1\/MVC-021S.JPG";
images[1][2][28] ="27917\/05262003_1\/MVC-022S.JPG";
images[1][2][0] ="28";
images[1][3][1] ="27917\/05302003\/MVC-001S.JPG";
images[1][3][2] ="27917\/05302003\/MVC-001S1.JPG";
images[1][3][3] ="27917\/05302003\/MVC-002S.JPG";
images[1][3][4] ="27917\/05302003\/MVC-002S1.JPG";
images[1][3][5] ="27917\/05302003\/MVC-003S.JPG";
images[1][3][6] ="27917\/05302003\/MVC-003S1.JPG";
images[1][3][7] ="27917\/05302003\/MVC-004S.JPG";
images[1][3][8] ="27917\/05302003\/MVC-004S1.JPG";
images[1][3][9] ="27917\/05302003\/MVC-005S.JPG";
images[1][3][10] ="27917\/05302003\/MVC-005S1.JPG";
images[1][3][11] ="27917\/05302003\/MVC-006S.JPG";
images[1][3][12] ="27917\/05302003\/MVC-006S1.JPG";
images[1][3][13] ="27917\/05302003\/MVC-007S.JPG";
images[1][3][14] ="27917\/05302003\/MVC-008S.JPG";
images[1][3][15] ="27917\/05302003\/MVC-009S.JPG";
images[1][3][16] ="27917\/05302003\/MVC-010S.JPG";
images[1][3][17] ="27917\/05302003\/MVC-011S.JPG";
images[1][3][18] ="27917\/05302003\/MVC-012S.JPG";
images[1][3][19] ="27917\/05302003\/MVC-013S.JPG";
images[1][3][20] ="27917\/05302003\/MVC-014S.JPG";
images[1][3][21] ="27917\/05302003\/MVC-015S.JPG";
images[1][3][22] ="27917\/05302003\/MVC-016S.JPG";
images[1][3][23] ="27917\/05302003\/MVC-017S.JPG";
images[1][3][24] ="27917\/05302003\/MVC-018S.JPG";
images[1][3][25] ="27917\/05302003\/MVC-019S.JPG";
images[1][3][26] ="27917\/05302003\/MVC-020S.JPG";
images[1][3][27] ="27917\/05302003\/MVC-021S.JPG";
images[1][3][28] ="27917\/05302003\/MVC-022S.JPG";
images[1][3][0] ="28";

// Set inital image count to 0
var totalimages = 0;

// Set location of images
var locale = "http\:\/\/customer.somedomain.com\/pics\/659423069\/";

// Function to show next picture if 'next' link is clicked
function nextpic() {
fileindex += 1;
if (fileindex > totalimages)
fileindex = 1;
document.pic.src = locale + images[jobindex][dateindex][fileindex];
}

// Function to show previous picture if 'previous' link is clicked.
function prevpic() {
fileindex -= 1;
if (fileindex < 1)
fileindex = totalimages;
document.pic.src = locale + images[jobindex][dateindex][fileindex];
}

// Function to set reference current pics to view
function setcurrent() {
totalimages= parseint(images[jobindex][dateindex][0]);
document.pic.src = locale + images[jobindex][dateindex][fileindex];
}


I have some HTML code that uses the onclick event handler, and the code being executed looks like this:

onClick="jobindex=1;dateindex=1;fileindex=1;setcurrent();"

Jona
06-03-2003, 09:42 AM
Try just looping through them after you declare all of their values.

Jona

yardleybates
06-03-2003, 09:49 AM
At the very top of your code, you have this loop

for (x=0; x < 1; x++)


Why are you using the loop as it will only execute once, effectively setting x = 0. Can't you just set the x value at 0 and eliminate 1 loop? Also, in the list of images, you have listed [1].... If I'm reading it correctly, you are setting that first value to 0, not 1.
I could be reading it wrong, though.

Jona
06-03-2003, 09:54 AM
No offense, and I'm not saying that you're a bad scripter, yardleybates, but the code looks kind of backwards to me. :rolleyes: I would've set all of the arrays and values first, then looped through them... But I guess that's just personal preference...

Jona

NetworkRanger
06-03-2003, 10:11 AM
I added the following code after the values are assigned to the images array.

// loop
for (x=0; x < 1; x++)
{
for (y=0; y < 3; y++)
{
for (z=0; z < 28; z++)
{
// do nothing;
}
}
}

Looping through the images array didn't throw an error. I don't get an error until I click one of the links that executes the onClick event handler.


yardleybates: The values of the for loops are programatically assigned. In this case the first array dimension just happens to be 1. Just like the value 3 and 28. Those values represent the highest possible value for each dimension.

The message seems to be generated from the "totalimages =" line in the setcurrent function. But, I don't see anything wrong there.

Jona
06-03-2003, 10:16 AM
Wait a second... You have var images = new Array(); right? Are you forgetting about document.images[]? Try changing the name of the array..

Jona

NetworkRanger
06-03-2003, 10:21 AM
yardleybates gave me an idea.

arrays start at 0 not 1.

assigning values to an array index that doesn't exist doesn't make sense. this is the case for each dimension in the array.

let me try this out and i will get back to you.

thanks.

Jona
06-03-2003, 10:23 AM
Um... I thought you already did that. :p

Good luck,
Jona

Khalid Ali
06-03-2003, 10:26 AM
There are few things that could be done better.
1. "27917\/05262003\/MVC-001S.JPG";

uyou do not need to escape the forward slash there so change the above line wherever it is to
"27917/05262003/MVC-001S.JPG";


2. Since you have al of your images named systamtically,you can pre load them in a loop, may be something like this
var images = new Array(3)
for(var n=0;n<3;n++){
images[n] = new Array(28);
for(var x=0;x<images[n].length;n++){
//now preload images
var img = new Image();
img.src = "27917/05262003/MVC-00"+(n+1)+"S.JPG";
}
}

once that part is taken care of then change this line

var locale = "http\:\/\/customer.somedomain.com\/pics\/659423069\/";

to this

var locale = "http://customer.somedomain.com/pics/659423069/";

I am pretty sure this will point you to your goal..

:D

NetworkRanger
06-03-2003, 10:43 AM
The array thing combined with the misspelling of parseInt took care of the problem.

Jona
06-03-2003, 10:48 AM
Glad it worked for ya. ;)

Jona