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

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

If a string doesn't contain a value, its length is set to undefined:
var thirdStr:String;
trace(thirdStr.length); // undefined
If your string contains a null byte character (\0), the string value will be truncated.
You can also use character codes to define a string. For more information on character codes
and character encoding, see
The following example creates a variable named
ASCII values passed to the
var myStr:String =
String.fromCharCode(104,101,108,108,111,32,119,111,114,108,100,33);
trace(myStr); // hello world!
Each number listed in the
character. For example, the ASCII value 104 represents a lowercase h, and the ASCII value 32
represents the space character.
You can also use the
String.fromCharCode()
the unicode value must be converted from hexidecimal to decimal values, as shown in the
following ActionScript:
// Unicode 0068 == "h"
var letter:Number = Number(new Number(0x0068).toString(10));
trace(String.fromCharCode(letter)); // h
You can examine the characters in various positions in a string, as in the following example.
To loop over a string:
1.
Create a new Flash document.
2.
Add the following ActionScript to Frame 1 of the main Timeline:
var myStr:String = "hello world!";
for (var i:Number = 0; i < myStr.length; i++) {
trace(myStr.charAt(i));
}
3.
Select Control > Test Movie to preview your Flash document. You should see each
character traced to the Output panel on a separate line.
"About strings and the String class" on page
String.fromCharCode()
method in the previous code represents a single
fromCharCode()
and sets the string's value based on
myStr
method:
method to convert Unicode values, although
About strings and the String class
450.
461

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