Feb 10 2009

Actionscript 3- Vector to Array

There’s currently no way to convert a Vector to an Array (or ArrayCollection), so here’s a simple util that’ll do it. Accepts any type within the Vector, so the parameter is just an Object, then we convert it back to a vector before the Array conversion. Phew.

public static function VectorToArray( v:Object ):Array
{
    var vec : Vector. = Vector.(v);
    var arr : Array = new Array()
    for each( var i : Object in vec ) {
        arr.push(i);
    }
    return arr;
}

Post to Twitter