The previous example shows how you can use the addition (+) and addition assignment (+=)
operators to concatenate strings. Notice how the third line of code uses the addition operator
to concatenate the value of the
uses the addition assignment operator to concatenate a string onto the existing value of the
text field.
If only one of the text string operands is actually a string, Flash converts the other operand
into a string. Therefore, the value of
ActionScript treats spaces at the beginning or end of a string as a literal part of the string.
Using dot and array access operators
You can use the dot operator (
ActionScript properties. You use dot operators to target certain indexes in an object. For
example, if you have an object that contains some user information, you can specify a certain
key name in the array access operator to retrieve a user's name, as demonstrated in the
following ActionScript:
var someUser:Object = {name:"Hal", id:2001};
trace("User's name is: " + someUser["name"]); // User's name is: Hal
trace("User's id is: " + someUser["id"]); // User's id is: 2001
For example, the following ActionScript uses the dot operator to set certain properties
within objects:
myTextField.border = true;
year.month.day = 9;
myTextField.text = "My text";
The dot operator and the array access operator are very similar. The dot operator takes an
identifier as its property, but the array access operator evaluates the contents to a name and
then accesses the value of that named property. The array access operator lets you dynamically
set and retrieve instance names and variables.
The array access operator is useful if you don't know exactly what keys are in an object. When
this occurs, you can use a
its contents.
To use dot and array access operators:
1.
In a new Flash document, create a movie clip on the main Timeline.
2.
Select the movie clip and open the Property inspector.
3.
Type in an instance name of myClip.
184
Syntax and Language Fundamentals
variable into the text field, and the fourth line of code
myNum
converts to a string in the previous example.
myNum
) and the array access operator (
.
loop to iterate through an object or movie clip and display
for..in
) to access built-in or custom
[]
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?