Addition Assignment Operator - MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE Reference

Actionscript 2.0 language reference
Table of Contents

Advertisement

Usage 3: Variables associated with dynamic and input text fields have the data type String. In
the following example, the variable
enters a deposit amount, the script attempts to add
because
is a String data type, the script concatenates (combines to form one string)
deposit
the variable values rather than summing them.
var oldBalance:Number = 1345.23;
var currentBalance = deposit_txt.text + oldBalance;
trace(currentBalance);
For example, if a user enters 475 in the deposit text field, the trace() statement sends the value
4751345.23 to the Output panel. To correct this, use the Number() function to convert the
string to a number, as in the following:
var oldBalance:Number = 1345.23;
var currentBalance:Number = Number(deposit_txt.text) + oldBalance;
trace(currentBalance);
The following example shows how numeric sums to the right of a string expression are not
calculated:
var a:String = 3 + 10 + "asdf";
trace(a); // 13asdf
var b:String = "asdf" + 3 + 10;
trace(b); // asdf310

+= addition assignment operator

expression1 += expression2
Assigns
expression1
two statements have the same result:
x += y;
x = x + y;
This operator also performs string concatenation. All the rules of the addition (+) operator
apply to the addition assignment
Availability: ActionScript 1.0; Flash Player 4
Operands
expression1 : Number
expression2 : Number
Returns
- The result of the addition.
Number
deposit
the value of
expression1+ expression2
operator.
(+=)
- A number or string.
- A number or string.
is an input text field on the Stage. After a user
to
deposit
oldBalance
. For example, the following
. However,
Operators
133

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flash 8

Table of Contents