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
// Allocation for Array | |
ArrayObject* ArrayClass::newarray(Atom* argv, int argc) | |
{ | |
ArrayObject *inst = newArray(argc); | |
for (uint32 i=0; i<uint32(argc); i++) { | |
inst->setUintProperty(i, argv[i]); | |
} | |
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
# Defining a class globally can be done like this: | |
class Foo | |
constructor: (@name) -> | |
this.Foo = Foo; | |
# Or like this... | |
this.Foo = class Foo | |
constructor: (@name) -> |
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
// 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; |
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
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); |
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
// 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; | |
} |
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 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 |
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 |
OlderNewer