Something about Vector in AS3 FP10
Vector is a new element in AS3. Basically it is an array with data of the same type. I will not repeat its difference with Array, its advantage, etc here since you can read them in the AS 3 Language Reference for FP 10 and senocular’s tutorial. I am going to highlight a few points about its syntax and usage.
Always remember to define the type
At least to me, this is a very common mistake. Just remember whenever and wherever u type the word “Vector”, it must be followed with “.<dataType>”. So remember it always looks like this:
Vector.<datatype>
2D Vector
Just like Array, Vector can be 2D. Say you want to store several lottery results in the Vector format. You can do the following:
var lottery:Vector.<Vector.<int>> = new Vector.<Vector.<int>>();
lottery.push(Vector.<int>([1,2,3,4,5,6]));
lottery.push(Vector.<int>([11,12,13,14,15,16]));
lottery.push(Vector.<int>([21,22,23,24,25,26]));
In the above example, “lottery” is a Vector with type “Vector.<int>”, i.e. each element of Vector store a list of integers. So for example, lottery[1] stores the list (i.e. vector) of integers from 11-16 and lottery[1][1] should return 12.
Vector() Global function
This is basically a function to change something into the Vector format. In the above lottery example, the lists of numbers in brackets [ ] are actually arrays (because for Vector you cannot define values with [ ] like in Array). So in the example we are actually changing the arrays of numbers into Vector of integer type, then push this vector into another vector “lottery”. You can refer to the AS3 Lang Ref for more details.