Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 235

Programming actionscript 3.0
Table of Contents

Advertisement

Querying an array
The remaining four methods of the Array class—
—all query the array for information, but do not modify the array. The
toString()
and
concat()
slice()
methods both return strings. The
arguments and combines it with the existing array to create a new array. The
has two parameters, aptly named
containing a copy of the elements "sliced" from the existing array. The slice begins with the
element at
startIndex
repeating: the element at
The following example uses
other arrays:
var array1:Array = ["alpha", "beta"];
var array2:Array = array1.concat("gamma", "delta");
trace(array2); // output: alpha,beta,gamma,delta
var array3:Array = array1.concat(array2);
trace(array3); // output: alpha,beta,alpha,beta,gamma,delta
var array4:Array = array3.slice(2,5);
trace(array4); // output: alpha,beta,gamma
You can use the
join()
as a string. If no parameters are used for the
identically—they return a string containing a comma-delimited list of all elements in the
array. The
method, unlike the
join()
, which allows you to choose the symbol to use as a separator between each element
delimiter
in the returned string.
The following example creates an array called
to return the values in the array as a string. The
comma-separated values (
separated by the
character.
+
var rivers:Array = ["Nile", "Amazon", "Yangtze", "Mississippi"];
var riverCSV:String = rivers.toString();
trace(riverCSV); // output: Nile,Amazon,Yangtze,Mississippi
var riverPSV:String = rivers.join("+");
trace(riverPSV); // output: Nile+Amazon+Yangtze+Mississippi
methods both return new arrays, while the
method takes a new array or list of elements as
concat()
startIndex
and ends with the element just before
is not included in the return value.
endIndex
and
concat()
slice()
and
methods to query the array and return its contents
toString()
join()
toString()
), while the
riverCSV
,
concat()
join()
and an
, and returns a new array
endIndex
endIndex
to create new arrays using elements of
method, the two methods behave
method, accepts a parameter named
and calls both
rivers
method is used to return
toString()
method is used to return values
join()
,
,
slice()
and
join()
toString()
method
slice()
. That bears
and
join()
toString()
Indexed arrays
235

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents