EasyManua.ls Logo

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

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...
About strings and the String class 459
To create and use strings:
1. Create a new Flash document and save it as strings.fla.
2. Add the following ActionScript to Frame 1 of the main Timeline:
var firstStr:String = "foo";
var secondStr:String = new String("foo");
trace(firstStr == secondStr); // true
var thirdStr:String;
trace(thirdStr); // undefined
This code defines three String objects, one that uses a string literal, one that uses the new
operator, and the other without an initial value. Strings can be compared by using the
equality (==) operator, as shown in the third line of code. When referring to variables, you
specify the data type only when the variable is being defined.
3. Select Control > Test Movie to test the document.
Always use string literals unless you specifically need to use a String object. For more
information on string literals and the String object, see Chapter 5, “About literals,” on
page 130.
To use single straight quotation mark (
') and double straight quotation mark (") delimiters
within a single string literal, use the backslash character (
\) to escape the character. The
following two strings are equivalent:
var firstStr:String = "That's \"fine\"";
var secondStr:String = 'That\'s "fine"';
For more information on using the backslash character in strings, see About the escape
character” on page 460.
Remember that you cannot use “curly quotation mark” or “special quotation mark” characters
within your ActionScript code; they are different from the straight quotation marks (
') and
(
") that you can use in your code. When you paste text from another source into
ActionScript, such as the web or a Word document, be sure to use straight quote delimiters.
You can find a sample source file, strings.fla, in the Samples folder on your hard disk. This file
shows you how to build a simple word processor that compares and retrieves string and
substring selections.
In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Strings.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Strings.

Table of Contents

Related product manuals