HairyTeeth
04-13-2003, 10:05 PM
The script below concatenates 2 image arrays and uses the third to preload images from both arrays. Take note of the bold text.
<script type="text/javascript" language="javascript">
<!--;
//dummy data
function cons(n,s){
this.n = n;
this.s=s;
}
imgArray_1 = new Array();
imgArray_1[0]=new cons('image_1.gif','some_param');
imgArray_1[1]=new cons('image_2.gif',some_param');
imgArray_2 = new Array('foo_1.gif','foo_2.gif','f00_3.gif');
function preloading(){
var tmpArray = new Array();
var imgSrc;
var pth="images/";
for(i=0;i<imgArray_1 .length;i++){
tmpArray[i] = imgArray_1 [i].n;
}
preloadArray=tmpArray.concat(imgArray_2);
for(j=0;j<preloadArray.length; j++){
imgSrc = pth + preloadArray[j];
preloadArray[j] = new Image();
preloadArray[j].src = imgSrc;
}
}
preloading()
//-->
</script>
However, If I state the image src like this (ater removing the imgSrc variable assignments)
preloadArray[j].src = pth + preloadArray[j]
...it returns (on my machine)
file:///c/...blah/images/[object]
instead of
file:///c/...blah/images/image_1.gif
Why is [object] returned instead of the file name? :confused:
<script type="text/javascript" language="javascript">
<!--;
//dummy data
function cons(n,s){
this.n = n;
this.s=s;
}
imgArray_1 = new Array();
imgArray_1[0]=new cons('image_1.gif','some_param');
imgArray_1[1]=new cons('image_2.gif',some_param');
imgArray_2 = new Array('foo_1.gif','foo_2.gif','f00_3.gif');
function preloading(){
var tmpArray = new Array();
var imgSrc;
var pth="images/";
for(i=0;i<imgArray_1 .length;i++){
tmpArray[i] = imgArray_1 [i].n;
}
preloadArray=tmpArray.concat(imgArray_2);
for(j=0;j<preloadArray.length; j++){
imgSrc = pth + preloadArray[j];
preloadArray[j] = new Image();
preloadArray[j].src = imgSrc;
}
}
preloading()
//-->
</script>
However, If I state the image src like this (ater removing the imgSrc variable assignments)
preloadArray[j].src = pth + preloadArray[j]
...it returns (on my machine)
file:///c/...blah/images/[object]
instead of
file:///c/...blah/images/image_1.gif
Why is [object] returned instead of the file name? :confused: