13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with strings<br />

Empty string A string that contains no text, white space, or other characters, writt<strong>en</strong> as "". An empty string value is<br />

differ<strong>en</strong>t from a String variable with a null value—a null String variable is a variable that does not have a String instance<br />

assigned to it, whereas an empty string has an instance with a value that contains no characters.<br />

String A textual value (sequ<strong>en</strong>ce of characters).<br />

String literal (or “literal string”) A string value writt<strong>en</strong> explicitly in code, writt<strong>en</strong> as a text value surrounded by double<br />

quotation marks or single quotation marks.<br />

Substring A string that is a portion of another string.<br />

Unicode A standard system for repres<strong>en</strong>ting text characters and symbols in computer programs. The Unicode system<br />

allows for the use of any character in any writing system.<br />

Creating strings<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The String class is used to repres<strong>en</strong>t string (textual) data in ActionScript 3.0. ActionScript strings support both ASCII<br />

and Unicode characters. The simplest way to create a string is to use a string literal. To declare a string literal, use<br />

straight double quotation mark (") or single quotation mark (') characters. For example, the following two strings are<br />

equival<strong>en</strong>t:<br />

var str1:String = "hello";<br />

var str2:String = 'hello';<br />

You can also declare a string by using the new operator, as follows:<br />

var str1:String = new String("hello");<br />

var str2:String = new String(str1);<br />

var str3:String = new String(); // str3 == ""<br />

The following two strings are equival<strong>en</strong>t:<br />

var str1:String = "hello";<br />

var str2:String = new String("hello");<br />

To use single quotation marks (') within a string literal defined with single quotation mark (') delimiters, use the<br />

backslash escape character (\). Similarly, to use double quotation marks (") within a string literal defined with double<br />

quotation marks (") delimiters, use the backslash escape character (\). The following two strings are equival<strong>en</strong>t:<br />

var str1:String = "That's \"A-OK\"";<br />

var str2:String = 'That\'s "A-OK"';<br />

You may choose to use single quotation marks or double quotation marks based on any single or double quotation<br />

marks that exist in a string literal, as in the following:<br />

var str1:String = "ActionScript 3.0";<br />

var str2:String = 'banana';<br />

Keep in mind that ActionScript distinguishes betwe<strong>en</strong> a straight single quotation mark (') and a left or right single<br />

quotation mark (' or ' ). The same is true for double quotation marks. Use straight quotation marks to delineate<br />

string literals. Wh<strong>en</strong> pasting text from another source into ActionScript, be sure to use the correct characters.<br />

As the following table shows, you can use the backslash escape character (\) to define other characters in string literals:<br />

Last updated 6/6/2012<br />

11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!