Archive for January, 2011

Populating a Vector in the constructor

Wednesday, January 19th, 2011

There is a small difference between populating a Vector while instancing it and an Array.
While an Array is instanced this way:

var names:Array = ["Bob", "Larry", "Sarah"];

a Vector can be instanced like this:

// In the constructor
var names:Vector.<String> = new <String>["Bob", "Larry", "Sarah"];
// Converting from a regular Array using the Vector global (about three times slower)
var names:Vector.<String> = Vector.<String>(["Bob", "Larry", "Sarah"]);