Fancy AS3 Vector class

It was about time for ActionScript and finally Flash player 10 comes with vectors or typed arrays. Very simple stuff, it's just an array in which all of its members have the same type. We had this for years both in MTASC and haXe because adds an extra layer of security at compile time against silly mistakes, so it's nice having it as part of AS3 too.

But with security and performance improvements come some restrictions. From the docs:

* A Vector is a dense array. Unlike an Array, which may have values in indices 0 and 7 even if there are no values in positions 1 through 6, a Vector must have a value (or null ) in each index.
* A Vector can optionally be fixed-length, meaning the number of elements it contains can't change.
* Access to a Vector's elements is bounds-checked. You can never read a value from an index greater than the final element ( length - 1 ). You can never set a value with an index more than one beyond the current final index (in other words, you can only set a value at an existing index or at index [length] ).


Careful with them because we are so used to the loose Array that most likely we are going to forget these limitations.

Also I'm liking a lot mixing the Vector class with the new for each loop. Like this:

[code lang="actionscript"]var wadusList:Vector.<Wadus>;

for each(var w:Wadus in wadusList){
// do something with w
}[/code]

Short, fast and strictly typed. I bet that the people that was casting even Strings in for loops love this. I know I am and I also know I'm going to get rid of 99% of my Arrays.

Back to index