I really want to like Vectors, the new typed array functionality in Flash 10. In fact, I use it as often as I can. But there are some really awkward things about it that make it a pain. Here are some gotchas:

The point of Vectors is supposed to be twofold: type safety and speed. In empirical tests, they do appear somewhat faster than Arrays, Dictionaries, and Objects. They don’t always hold up so well in the type safety category though. Consider this obvious typo:

var vec:Vector.<int> = new Vector.<String>();

That seems like about the most obvious compiler error you could imagine, right? Wrong. You don’t get a compiler error or warning, but instead a runtime exception:

TypeError: Error #1034

How about if you try to put an incorrect type in the Vector?

var vec:Vector.<DisplayObject> = new Vector.<DisplayObject>();
vec.push(33);
vec.unshift(33);

Both of these result in the same TypeError as above! How about this?

var vec:Vector.<DisplayObject> = new Vector.<DisplayObject>();
vec[0] = 33;
var val:int = vec[0];

Sanity prevails here and you actually get compiler errors:

Error: Implicit coercion of a value of type int to an unrelated type flash.display:DisplayObject.

and

Error: Implicit coercion of a value of type flash.display:DisplayObject to an unrelated type int.

So what makes push() and unshift() so different that they give compiler errors and warnings? The answer is that they will both take as many elements as you want to push/unshift onto the Vector. Since this is untyped, your error isn’t caught until runtime.

Ultimately, Vectors are type-safe. Stronger type safety like you get in C++ and Java still eludes AS3. The trick, until the situation changes, is to know the above subtleties of Vector so you’re not caught with a crash.