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.

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

slice (String.slice method)<br />

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

Returns a string that includes the start character <strong>and</strong> all characters up to, but not including,<br />

the end character. The original String object is not modified. If the end parameter is not<br />

specified, the end of the substring is the end of the string. If the character indexed by start is<br />

the same as or to the right of the character indexed by end, the method returns an empty<br />

string.<br />

Parameters<br />

start:Number - The zero-based index of the starting point for the slice. If start is a negative<br />

number, the starting point is determined from the end of the string, where -1 is the last<br />

character.<br />

end:Number - An integer that is one greater than the index of the ending point for the slice.<br />

The character indexed by the end parameter is not included in the extracted string. If this<br />

parameter is omitted, String.length is used. If end is a negative number, the ending point is<br />

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

Returns<br />

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

Example<br />

The following example creates a variable, my_str, assigns it a String value, <strong>and</strong> then calls the<br />

slice() method using a variety of values for both the start <strong>and</strong> end parameters. Each call to<br />

slice() is wrapped in a trace() statement that displays the output in the Output panel.<br />

// Index values for the string literal<br />

// positive index: 0 1 2 3 4<br />

// string: L o r e m<br />

// negative index: -5 -4 -3 -2 -1<br />

var my_str:String = "Lorem";<br />

// slice the first character<br />

trace("slice(0,1): "+my_str.slice(0, 1)); // output: slice(0,1): L<br />

trace("slice(-5,1): "+my_str.slice(-5, 1)); // output: slice(-5,1): L<br />

// slice the middle three characters<br />

String 599

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

Saved successfully!

Ooh no, something went wrong!