+ (addition)
Availability
Flash Player 4; Flash Player 5. In Flash 5 and later,
concatenator depending on the data type of the parameter. In Flash 4,
operator. Flash 4 files brought into the Flash 5 or later authoring environment undergo a
conversion process to maintain data type integrity. The following example illustrates the
conversion of a Flash 4 file containing a numeric quality comparison:
Flash 4 file:
x + y
Converted Flash 5 or later file:
Number(x) + Number(y)
Usage
expression1 + expression2
Parameters
expression1,expression2
Returns
None.
Description
Operator; adds numeric expressions or concatenates (combines) strings. If one expression is a
string, all other expressions are converted to strings and concatenated.
If both expressions are integers, the sum is an integer; if either or both expressions are floating-
point numbers, the sum is a floating-point number.
Example
Usage 1: The following example concatenates two strings and displays the result in the
Output panel.
name = "Cola";
instrument = "Drums";
trace (name + " plays " + instrument);
Usage 2: Variables associated with dynamic and input text fields have the data type String. In the
following example, the variable
deposit amount, the script attempts to add
is a String data type, the script concatenates (combines to form one string) the variable values
rather than summing them.
oldBalance = 1345.23;
currentBalance = deposit + oldBalance;
trace (currentBalance);
For example, if a user enters 475 in the deposit text field, the
4751345.23 to the Output panel.
To correct this, use the
currentBalance = Number(deposit) + oldBalance;
252
Chapter 12: ActionScript Dictionary
A number or string.
is an input text field on the Stage. After a user enters a
deposit
deposit
function to convert the string to a number, as in the following:
Number()
is either a numeric operator or string
+
is only a numeric
+
to
. However, because
oldBalance
action sends the value
trace()
deposit
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?
Questions and answers