Tutorial by Examples

Type casting is done with either the as operator: var chair:Chair = furniture as Chair; Or by wrapping the value in Type(): var chair:Chair = Chair(furniture); If the cast fails with as, the result of that cast is null. If the cast fails by wrapping in Type(), a TypeError is thrown.
Functions are of the type Function: function example():void { } trace(example is Function); // true They can be referenced by other variables with the type Function: var ref:Function = example; ref(); // ref.call(), ref.apply(), etc. And they can be passed in as arguments for parameters wh...
References to class declarations are typed Class: var spriteClass:Class = Sprite; You can use variables typed Class to instantiate instances of that class: var sprite:Sprite = new spriteClass(); This can be useful for passing an argument of type Class to a function that might create and inst...
You can tell the compiler the type of a value by annotating it with :Type: var value:int = 10; // A property "value" of type "int". Function parameters and return types can also be annotated: // This function accepts two ints and returns an int. function sum(a:int, b:int):i...
You can use the is operator to validate whether a value is of a certain type: var sprite:Sprite = new Sprite(); trace(sprite is Sprite); // true trace(sprite is DisplayObject); // true, Sprite inherits DisplayObject trace(sprite is IBitmapDrawable); // true, DisplayObject implements IBitmapDra...
Unfortunately ActionScript 3 does not have a concept of generics, so it follows that there is no way to define a typed array as Array<T>. There is however a special class Vector.<T> which works in a similar way except you must provide a reference to a concrete class when instantiating th...

Page 1 of 1