11 Jun

When I read that Adobe were adding strongly typed arrays to the SDK, I was overjoyed.  This functionality alone would save me days of time on every project, as well as allowing code hint to show me what operations I can perform on the array elements.

But alas, it doesn’t quite hit the mark. 

You can easily specify the element type of a vector:

var vect:Vector.<Sprite> = new Vector.<Sprite>();

But as stated in the documentation, the push method (which is the only way of adding a new element to a Vector without doing some clumsy coding) DOES NOT do type checking at compile time:

“Because this function can accept multiple arguments, the data type of the arguments is not checked at compile time even in strict mode”

So this compiles fine:

var vect:Vector.<Sprite> = new Vector.<Sprite>();
vect.push(new Skin());

Admittedly this will throw a run-time error, but that’s not really good enough.

In Adobe's defense, this will fail at compile time:

var vect:Vector.<Sprite> = new Vector.<Sprite>();
vect[0] = new Skin();

Additionally, code hints for the most part pick up the type, but it’s just not where it needs to be IMO.

All content © 2009-2011 Matthew Butt. All views expressed herein are my own and do not represent the views of my employer, AREA203 Digital.