Object.toString()
Availability
Flash Player 5.
Usage
myObject.toString() : String
Parameters
None.
Returns
A string.
Description
Method; converts the specified object to a string and returns it.
Example
This example shows the return value for toString() on a generic object:
var myObject:Object = new Object();
trace(myObject.toString()); // output: [object Object]
This method can be overridden to return a more meaningful value. The following examples show
that this method has been overridden for the built-in classes Date, Array, and Number:
// Date.toString() returns the current date and time
var myDate:Date = new Date();
trace(myDate.toString()); // output: [current date and time]
// Array.toString() returns the array contents as a comma-delimited string
var myArray:Array = new Array("one", "two");
trace(myArray.toString()); // output: one,two
// Number.toString() returns the number value as a string
// Because trace() won't tell us whether the value is a string or number
// we will also use typeof() to test whether toString() works.
var myNumber:Number = 5;
trace(typeof (myNumber));
trace(myNumber.toString()); // output: 5
trace(typeof (myNumber.toString())); // output: string
The following example shows how to override
file named Vehicle.as that contains only the Vehicle class definition and place it into your Classes
folder inside your Configuration folder.
// contents of Vehicle.as
class Vehicle {
var numDoors:Number;
var color:String;
function Vehicle(param_numDoors:Number, param_color:String) {
this.numDoors = param_numDoors;
this.color = param_color;
672
Chapter 2: ActionScript Language Reference
// output: number
toString()
in a custom class. First create a text
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?