Skip to content

Instantly share code, notes, and snippets.

View mbolt35's full-sized avatar
:octocat:
Code, code, code...

Matt Bolt mbolt35

:octocat:
Code, code, code...
View GitHub Profile
var vec3:Vector.<int> = new <int>[ 9, 8, 7 ];
result = vec.concat(vec2, vec3);
trace(result);
// Outputs: 1,2,3,3,2,1,9,8,7
var vec:Vector.<int> = new <int>[ 1, 2, 3 ];
var vec2:Vector.<int> = new <int>[ 3, 2, 1 ];
var result:Vector.<int> = vec.concat(vec2);
trace(result);
// Outputs: 1,2,3,3,2,1
// ...
var arr3:Array = [ 9, 8, 7 ];
result = arr.concat(arr2, arr3);
trace(result);
// Outputs: 1,2,3,3,2,1,9,8,7
var arr:Array = [ 1, 2, 3 ];
var arr2:Array = [ 3, 2, 1 ];
var result:Array = arr.concat(arr2);
trace(result);
// Outputs: 1,2,3,3,2,1
public static function vectorToArray(vector:*):Array {
if (!isVector(vector)) {
throw new ArgumentError("Illegal argument, non-Vector for use with vectorToArray().");
}
var result:Array = [];
for (var i:int = 0; i < vector.length; ++i) {
result[i] = vector[i];
}
return result;
// This constant is set to the fully qualified class name for Vector
private static const VECTOR_CLASS:String = "__AS3__.vec::Vector";
// Use flash.utils.describeType() on the input, and verify type
// of the object is a Vector class. This is probably fairly
// expensive, a valid point to my argument.
public static function isVector(vector:*):Boolean {
var type:String = flash.utils.describeType(vector).@name;
return type.indexOf(VECTOR_CLASS) != -1;
}
var vec:Vector. = new <int>[ 1, 2, 3 ];
var arr:Array = function(v:Vector.<int>):Array {
var result:Array = [];
for (var i:int = 0; i < v.length; ++i) {
result[i] = v[i];
}
return result;
}(vec);
public static function vectorToArray(vector:*):Array {
var result:Array = [];
for (var i:int = 0; i < vector.length; ++i) {
result[i] = vector[i];
}
return result;
}
var arr:Array = [ 1, 2, 3 ];
var vec:Vector.<int> = Vector.<int>(arr);
trace(vec);
// Outputs: 1,2,3
// These produce the same Array *structure*, they are not
// strictly equivalent (===)
var oneWay:Array = new Array(1, 2, 3);
var anotherWay:Array = [ 1, 2, 3 ];
// Each of these result with the same Vector.<int>
// *structure*, however they are not strictly
// equivalent (===).
var v1:Vector.<int> = new Vector.<int>(3);
v1[0] = 1; v1[1] = 2; v1[2] = 3;