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 />

Wh<strong>en</strong> you run this code, the following output is produced:<br />

h - 104<br />

e - 101<br />

l - 108<br />

l - 108<br />

o - 111<br />

- 32<br />

w - 119<br />

o - 111<br />

r - 114<br />

l - 108<br />

d - 100<br />

! - 33<br />

You can also use character codes to define a string using the fromCharCode() method, as the following example<br />

shows:<br />

var myStr:String = String.fromCharCode(104,101,108,108,111,32,119,111,114,108,100,33);<br />

// Sets myStr to "hello world!"<br />

Comparing strings<br />

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

You can use the following operators to compare strings: . These operators can be used with<br />

conditional statem<strong>en</strong>ts, such as if and while, as the following example shows:<br />

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

var str2:String = "apple";<br />

if (str1 < str2)<br />

{<br />

trace("A < a, B < b, C < c, ...");<br />

}<br />

Wh<strong>en</strong> using these operators with strings, ActionScript considers the character code value of each character in the<br />

string, comparing characters from left to right, as in the following:<br />

trace("A" < "B"); // true<br />

trace("A" < "a"); // true<br />

trace("Ab" < "az"); // true<br />

trace("abc" < "abza"); // true<br />

Use the == and != operators to compare strings with each other and to compare strings with other types of objects, as<br />

the following example shows:<br />

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

var str1b:String = "1";<br />

var str2:String = "2";<br />

trace(str1 == str1b); // true<br />

trace(str1 == str2); // false<br />

var total:uint = 1;<br />

trace(str1 == total); // true<br />

Last updated 6/6/2012<br />

13

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

Saved successfully!

Ooh no, something went wrong!