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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Working with strings<br />

Converting strings betwe<strong>en</strong> uppercase and lowercase<br />

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

As the following example shows, the toLowerCase() method and the toUpperCase() method convert alphabetical<br />

characters in the string to lowercase and uppercase, respectively:<br />

var str:String = "Dr. Bob Roberts, #9."<br />

trace(str.toLowerCase()); // dr. bob roberts, #9.<br />

trace(str.toUpperCase()); // DR. BOB ROBERTS, #9.<br />

After these methods are executed, the source string remains unchanged. To transform the source string, use the<br />

following code:<br />

str = str.toUpperCase();<br />

These methods work with ext<strong>en</strong>ded characters, not simply a–z and A–Z:<br />

var str:String = "José Barça";<br />

trace(str.toUpperCase(), str.toLowerCase()); // JOSÉ BARÇA josé barça<br />

Strings example: ASCII art<br />

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

This ASCII Art example shows a number of features of working with the String class in ActionScript 3.0, including the<br />

following:<br />

The split() method of the String class is used to extract values from a character-delimited string (image<br />

information in a tab-delimited text file).<br />

Several string-manipulation techniques, including split(), concat<strong>en</strong>ation, and extracting a portion of the string<br />

using substring() and substr(), are used to capitalize the first letter of each word in the image titles.<br />

The getCharAt() method is used to get a single character from a string (to determine the ASCII character<br />

corresponding to a grayscale bitmap value).<br />

String concat<strong>en</strong>ation is used to build up the ASCII art repres<strong>en</strong>tation of an image one character at a time.<br />

The term ASCII art refers to a text repres<strong>en</strong>tations of an image, in which a grid of monospaced font characters, such<br />

as Courier New characters, plots the image. The following image shows an example of ASCII art produced by the<br />

application:<br />

Last updated 6/6/2012<br />

19

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

Saved successfully!

Ooh no, something went wrong!