252
Chapter 12: ActionScript Dictionary
+ (addition)
Availability
Flash Player 4; Flash Player 5. In Flash 5 and later,
+
is either a numeric operator or string
concatenator depending on the data type of the parameter. In Flash 4,
+
is only a numeric
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
A number or string.
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
is an input text field on the Stage. After a user enters a
deposit amount, the script attempts to add
deposit
to
oldBalance
. However, because
deposit
is a String data type, the script concatenates (combines to form one string) the variable values
rather than summing them.
oldBalance = 1345.23;
currentBalance = d oldBalance;
trace (currentBalance);
For example, if a user enters 475 in the deposit text field, the
trace()
action 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:
currentBalance = Number(deposit) + oldBalance;
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...