Addition Assignment Operator - MACROMEDIA FLASHLITE2 ACTIONSCRIPT-LANGUAGE Reference

Actionscript 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
value 4751345.23 to the Output panel. To correct this, use the
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 Lite 1.0
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
trace()
Number()
. For example, the following
. However,
function sends the
function to convert
Operators
119

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flash lite 2

Table of Contents