Little Thing About Arrays

This drove me crazy because the error messages weren’t related to this … but when you make an array in Actionscript you need to initialize it create an instance of it to make it useful. In retrospect this is completely obvious, but I didn’t pick up on it. Sigh.

// -- DOES NOT WORK:
var myArray:Array; // not initialized for use as an array
myArray.push('lemonade');

// -- WORKS:
var myArray:Array = new Array(); // for the love of god, do this.
myArray.push('pretzels');

I was running into a problem where none of the array methods (eg: pop/push/unshift/etc/) were working because I forgot to do this. I am an idiot and wasted a lot of time.

Interestingly, you can do this with no problems:

var myArray:Array; // not initialized for use as an array
myArray = ['red', 'green', 'blue', 'ass']; // array literal format