Monday, January 21, 2013

Casting to String

Casting to the String data type from any of the numeric data types returns a string representation of the number. Casting to the String data type from a Boolean value returns the string “true” if the value is true, and returns the string “false” if the value is false.

Casting to the String data type from an instance of the Object class returns the string “null” if the instance is null. Otherwise, casting to the String from the Object class returns the string “[object Object]”.

Casting to String from an instance of the Array class returns a string comprising a commadelimited list of all the array elements. For example, the following cast to the String data type returns one string containing all three elements of the array.
var myArray:Array = ["primary", "secondary", "tertiary"];
trace(String(myArray)); // output: primary,secondary,tertiary
Casting to String from an instance of the Date class returns a string representation of the date that the instance contains. For example, the following example returns a string representation of the Date class instance (output shows result for Pacific Daylight Time).
var myDate:Date = new Date(2005,6,1);
trace(String(myDate)); // output: Fri Jul 1 00:00:00 GMT-0700 2005
Programming Actionscript 3. Powered by Blogger.