Type Casting is the process of converting/transforming the value of a one datatype into another datatype's value. For example, you can use the movie clip as sprite using "as" in AS3.

To change the type of number and string we can use the following codes.

// Changing a number as string
var myNum:Number = 10;
var myStr:String = String(myNum)
trace(myStr);

// Changing a Boolean value as Number
var myBool:Boolean = true;
var myNum:Number = Number(myBool);
trace(myNum);

Typecasting in AS3 is even simpler than as2. We can use "as" to type casting. For example, if you want to change an object to array, it is very easy in AS3.

// Changing a object to an Array
var obj:Object = new Object();
obj = [1,2,3,4];
var b:Array = new Array()
b = obj as Array;
trace(b);




Leave a Reply.