Forum Moderators: open
I have created some functions that use arrays, but their size depends on situations that accour later. So at first i declare a empty array and later in my code i make new array of correct size. But still it says my array is not defined. Here is the script:
<SCRIPT LANGUAGE= JavaScript> <!--
var pics=new array(); //first error
var imgObjs=new array();
function preload(pics){
var imgObjs=new array(pics.length); //second error
for (i=0; i<pics.length; i++){
imgObjs[i]=new Image();
imgObjs[i].src=pics[i];
}
}
//-->
</SCRIPT>
...
some php and html
...
<script language="JavaScript"><!--
var size=37;
var pics = new Array(size);
//assign picture src to array elements
preload(pics);
//-->
</script>
new array() should be....
new Array()
birdbrain
var size=37;
var pics = new Array(size);
//assign picture src to array elements
Assigning a 'size' to an array in Javascript is not necessary. Javascript arrays are 'sparse'. They are very much unlike Java arrays. Assigning a length at time of creation only sets the length property, it doesn't create null or undefined members.
You might normally add a new member to an array like this:
myArray[myArray.length] = aMember
This will fail if you have preset the length.
What I'm saying is "don't bother setting the length".
Thank you Bernard for
your kind appreciation
of my presentational
skills ;) ;) ;) ;) ;)