EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 464

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
464 Working with Text and Strings
Converting and concatenating strings
You can use the toString() method to convert many objects to strings. Most built-in objects
have a
toString() method for this purpose:
var n:Number = 0.470;
trace(typeof(n.toString())); // string
When you use the addition (+) operator with a combination of string and nonstring instances,
you dont need to use the
toString() method. For details on concatenation, see the second
procedure in this section.
The
toLowerCase() method and the toUpperCase() method convert alphabetical characters
in the string to lowercase and uppercase, respectively. The following example demonstrates
how to convert a string from lowercase to uppercase characters.
To convert a string from lowercase to uppercase:
1. Create a new Flash document and save it as convert.fla.
2. Type the following code on Frame 1 of the Timeline:
var myStr:String = "Dr. Bob Roberts, #9.";
trace(myStr.toLowerCase()); // dr. bob roberts, #9.
trace(myStr.toUpperCase()); // DR. BOB ROBERTS, #9.
trace(myStr); // Dr. Bob Roberts, #9.
3.
Save the Flash document and select Control > Test Movie.
myStr = myStr.toUpperCase();
When you concatenate strings, you take two strings and join them sequentially into one
string. For example, you can use the addition (
+) operator to concatenate two strings. The
next example shows you how to concatenate two strings.
To concatenate two strings:
1. Create a new Flash document and save it as concat.fla.
2. Add the following code to Frame 1 of the Timeline:
var str1:String = "green";
var str2:String = str1 + "ish";
trace(str2); // greenish
//
var str3:String = "yellow";
str3 += "ish";
trace(str3); // yellowish
NOTE
After these methods are executed, the source string remains unchanged. To
transform the source string, use the following:

Table of Contents

Related product manuals