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.<object> = Vector.<object>(v);
- var arr : Array = new Array()
- for each( var i : Object in vec ) {
- arr.push(i);
- }
- return arr;
- }
- </object></object>
2 Responses to “Actionscript 3- Vector to Array”
Hi there!Just found this post. Am I allowed to clean and speed it up a bit?
public static function VectorToArray( v:Object ):Array
{
var vec : Vector. = v as Vector.,
arr : Array = [];
for each( var i : Object in vec )
{
arr[arr.length] = i;
}
return arr;
}
Cheers,
Daniel