03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

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.

substr (String.substr method)<br />

public substr(start:Number, length:Number) : String<br />

Returns the characters in a string from the index specified in the start parameter through the<br />

number of characters specified in the length parameter. The substr method does not change<br />

the string specified by my_str; it returns a new string.<br />

Parameters<br />

start:Number - An integer that indicates the position of the first character in my_str to be<br />

used to create the substring. If start is a negative number, the starting position is determined<br />

from the end of the string, where the -1 is the last character.<br />

length:Number - The number of characters in the substring being created. If length is not<br />

specified, the substring includes all the characters from the start to the end of the string.<br />

Returns<br />

String - A substring of the specified string.<br />

Example<br />

The following example creates a new string, my_str <strong>and</strong> uses substr() to return the second<br />

word in the string; first, using a positive start parameter, <strong>and</strong> then using a negative start<br />

parameter:<br />

var my_str:String = new String("Hello world");<br />

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

mySubstring = my_str.substr(6,5);<br />

trace(mySubstring); // output: world<br />

mySubstring = my_str.substr(-5,5);<br />

trace(mySubstring); // output: world<br />

An example is also in the Strings.fla file in the ActionScript samples folder at<br />

www.adobe.com/go/learn_fl_samples. Download <strong>and</strong> decompress the .zip file <strong>and</strong> navigate to<br />

the folder for your version of ActionScript to access the sample.<br />

substring (String.substring method)<br />

public substring(start:Number, end:Number) : String<br />

Returns a string comprising the characters between the points specified by the start <strong>and</strong> end<br />

parameters. If the end parameter is not specified, the end of the substring is the end of the<br />

string. If the value of start equals the value of end, the method returns an empty string. If<br />

the value of start is greater than the value of end, the parameters are automatically swapped<br />

before the function executes <strong>and</strong> the original value is unchanged.<br />

602 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!