MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 465

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

The preceding code shows two methods of concatenating strings. The first method uses
the addition (+) operator to join the
method uses the addition and assignment (+=) operator to concatenate the string
with the current value of
3.
Save the Flash document and select Control > Test Movie.
You can also use the
concat()
is demonstrated in the following example.
To concatenate two strings with the concat() method:
1.
Create a new Flash document and save it as concat2.fla.
2.
Add the following code to Frame 1 of the Timeline:
var str1:String = "Bonjour";
var str2:String = "from";
var str3:String = "Paris";
var str4:String = str1.concat(" ", str2, " ", str3);
trace(str4); // Bonjour from Paris
3.
Select Control > Test Movie to test the Flash document.
If you use the addition (
string and a nonstring object, ActionScript automatically converts nonstring objects to strings
in order to evaluate the expression. This conversion is demonstrated in the following
code example:
var version:String = "Flash Player ";
var rel:Number = 8;
version = version + rel;
trace(version); // Flash Player 8
However, you can use parentheses to force the addition (+) operator to evaluate arithmetically,
as demonstrated in the following ActionScript code:
trace("Total: $" + 4.55 + 1.46); // Total: $4.551.46
trace("Total: $" + (4.55 + 1.46)); // Total: $6.01
You can use the
split()
based on a delimiter character. For example, you could segment a comma- or tab-delimited
string into multiple strings.
For example, the following code shows how you can split an array into substrings by using the
ampersand (
) character as a delimiter.
&
str1
.
str3
method of the String class to concatenate strings. This method
) operator (or the addition and assignment [
+
method to create an array of substrings of a string, which is divided
string with the string
About strings and the String class
. The second
"ish"
"ish"
] operator) with a
+=
465

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

This manual is also suitable for:

Flash 8

Table of Contents