The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.36 / 5.00 33,851 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 12,195 ViewsSo I have this array and the length property of it doesn't seem to be working when i make it have one number, the length is that number:
var primary:Array = new Array(5);
trace(primary.length)//outputs 5
but when i have two numbers in it, the length property works:
var primary:Array = new Array(5,0);
trace(primary.length)//outputs 2
What am I doing wrong?
Don't worry. That's supposed to happen.
When you make an array with one value, it tells flash that the value is the number of elements in said array. If you make one with two or more, those values become the elements in that array.
If you want an array with a single value put:
var primary:Array = new Array();
primary[0] = 5;
trace(primary.length);
This outputs 1.
For more info read this
To make an array I suggest using the square bracket operators. You can do this:
var list:Array = [5];
That will make the array with just one value, the number 5. Apparently it's also slightly faster to create an array with that than using the Array() function like you did; probably because it doesn't check for amount of arguments and whether to create the list with the arguments as elements or as the length :p
Sup, bitches :)