I am trying to define an array with single element... so,
var arr:Array = new Array(1,2,3,4) // arr[0] = 1
// but
var arr:Array = new Array(1) // arr[0] = undefined
//Also,
var arr:Array = new Array([1]) // arr[0] = 1 , << ILLUSION
//Because, arr[0] is NOT A NUMBER, IT ITSELF IS OF TYPE=> ARRAY.
var arr:Array = [1] //arr[0]=1 but i think it's AS1.0 notation..
So, is their any AS3.0 way of defining array with single element ?
var arr:Array = [1]; //arr[0]=1 but i think it's AS1.0 notation..
Why? This is perfectly legal shorthand array initialization, and it's exactly the way to do it.
Lol, I remember dealing with this a year or 2 back, the way I did it was with 2 lines.
var arr:Array = new Array();
arr[0] = "the element";
This is because the constructor for Array accepts the size of the array as an argument if you are passing a single integer value. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#Array()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With