Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Classes > About working with built-in classes > Accessing built-in object properties | |||
Use the dot (.) operator to access the value of a property in an object. Put the name of the object on the left side of the dot, and put the name of the property on the right side. For example, in the following statement, my_obj is the object and firstName is the property:
my_obj.firstName
The following code creates a new Array object and then shows its length property:
var my_array:Array = new Array("apples", "oranges", "bananas");
trace(my_array.length); // 3
You can also use the array access operator ([]) to access the properties of an object, such as using the array access operator for debugging purposes. The following example loops over an object to display each of its properties.
To loop over the contents of an object:
var results:Object = {firstName:"Tommy", lastName:"G", age:7, avg:0.336, b:"R", t:"L"};
for (var i:String in results) {
trace("the value of [" + i + "] is: " + results[i]);
}
The previous code defines a new Object named results and defines values for firstName, lastName, age, avg, b, and t. A for..in loop traces each property in the results object and traces their value to the Output panel.
For more information on operators, including dot and array access operators, see About operators. For more information on methods and properties, see Functions and Methods. For examples of working with properties of the built-in MovieClip class, see Working with Movie Clips For examples of working with the properties of the TextField, String, TextRenderer, and TextFormat classes, see Working with Text and Strings.
|
|
|
|