This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr:Array = [ 1, 2, 3 ]; | |
var vec:Vector.<int> = Vector.<int>(arr); | |
trace(vec); | |
// Outputs: 1,2,3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function vectorToArray(vector:*):Array { | |
var result:Array = []; | |
for (var i:int = 0; i < vector.length; ++i) { | |
result[i] = vector[i]; | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
var arr3:Array = [ 9, 8, 7 ]; | |
result = arr.concat(arr2, arr3); | |
trace(result); | |
// Outputs: 1,2,3,3,2,1,9,8,7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr:Array = [ 1, 2, 3 ]; | |
var arr2:Array = [ 3, 2, 1 ]; | |
var result:Array = arr.concat(arr2, 4, 5, 6); | |
trace(result); | |
// Outputs: 1,2,3,3,2,1,4,5,6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vec:Vector.<int> = new <int>[ 1, 2, 3 ]; | |
var result:Vector.<int> = vec.concat(3, 2, 1); | |
trace(result); | |
// Unfortunately, this code ERRORS with: "Type Coercion failed" | |
// Cannot convert 3 to __AS3__.vec.Vector.<int>." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* So, if I want to create a new Vector.<int> that | |
* appends 3, 2, 1 without modifying the original, | |
* I need to create *another* new Vector.<int>, just | |
* to pass the values to concat(). That's one extra | |
* Vector.<int> instantiation. Three total Vector.<int> | |
* objects, while only 2 should be needed: | |
* -- One, the original vec:Vector.<int>. | |
* -- Two, the new <int>[ 3, 2, 1 ] to pass the concat() | |
* parameter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vec:Vector.<int> = new <int>[ 1, 2, 3, 4, 5 ]; | |
vec.sort(shuffle); | |
trace(vec); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vec:Vector.<int> = new <int>[ 1, 2, 3, 4, 5 ]; | |
vec.sort(Array.DESCENDING); | |
trace(vec); | |
// Outputs: 5,4,3,2,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package { | |
public class MyObject { | |
public var alpha:String = ""; | |
public var val:int = 0; | |
public function MyObject(alpha:String, val:int) { | |
this.alpha = alpha; | |
this.val = val; | |
} | |