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

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

4.
Modify the existing ActionScript code so that it traces the ASCII value for each character:
var myStr:String = "hello world!";
for (var i:Number = 0; i < myStr.length; i++) {
trace(myStr.charAt(i) + " - ASCII=" + myStr.charCodeAt(i));
}
5.
Save the current Flash document and select Control > Test Movie to preview the SWF file.
When you run this code, the following is displayed in the Output panel:
h - ASCII=104
e - ASCII=101
l - ASCII=108
l - ASCII=108
o - ASCII=111
- ASCII=32
w - ASCII=119
o - ASCII=111
r - ASCII=114
l - ASCII=108
d - ASCII=100
! - ASCII=33
You can also split a string into an array of characters by using the String.split()
method and entering an
charArray:Array = myStr.split("");
You can use operators to compare strings. For information on using operators with strings, see
"About using operators with strings" on page
You can use these operators with conditional statements, such as
example uses operators and strings to make a comparison.
To compare two strings:
1.
Create a new Flash document and save it as comparestr.fla.
2.
Add the following ActionScript to Frame 1 of the main Timeline:
var str1:String = "Apple";
var str2:String = "apple";
if (str1 < str2) {
trace("Uppercase letters sort first.");
}
3.
Save the Flash document and select Control > Test Movie to test the SWF file.
You can use the equality (
types of objects, as shown in the following example.
462
Working with Text and Strings
empty string ("")
182.
) and inequality (
==
!=
as a delimiter; for example,
and
if
) operators to compare strings with other
var
. The following
while

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