toString (String.toString メソッド)

public toString() : String

プロパティがストリングかどうかに関係なく、オブジェクトのプロパティをストリングとして返します。

使用できるバージョン : ActionScript 1.0、Flash Lite 2.0

戻り値

String - ストリング。

次の例では、プロパティがストリングであるかどうかに関係なく、オブジェクトのプロパティをすべてリストする大文字のストリングを出力します。

var employee: Object = new Object();
employee.name = "bob";
employee.salary = 60000;
employee.id = 284759021;

var employeeData: String = new String();
for (prop in employee) 
{
    employeeData += employee[prop].toString().toUpperCase() + " ";
}
trace(employeeData);

toString() メソッドがこのコードに含まれず、for ループ内の行で employee[prop].toUpperCase() を使用した場合、出力は "undefined undefined BOB" になります。toString() メソッドを指定すると、目的の出力 "284759021 60000 BOB" が生成されます。