TypedArray

Kind of class:public dynamic final class
Package:com.bourre.collection
Inherits from:Proxy
Implements:
Classpath:com.bourre.collection.TypedArray
File last modified:Monday, 24 November 2008, 11:36:49

Summary


Constructor
  • TypedArray (t:Class = null, args)
    • Create a new TypedArray instance.
Instance methods
  • push (args) : Number
    • Adds one or more elements to the end of an array and returns
  • unshift (args) : Number
    • Adds one or more elements to the beginning of an array
  • splice (startIndex:int, deleteCount:int, values) : TypedArray
    • Adds elements to and removes elements from an array.
  • concat (args) : TypedArray
    • Concatenates the elements specified in the parameters with
  • slice (startIndex:int, endIndex:int) : TypedArray
    • Returns a new array that consists of a range of elements from the original array,
  • filter (callback:Function, thisObject:* = null) : TypedArray
    • Executes a test function on each item in the array and constructs a new array
  • map (callback:Function, thisObject:* = null) : TypedArray
    • Executes a function on each item in an array, and constructs a new array
  • sort (args) : TypedArray
    • Sorts the elements in an array.
  • sortOn (fieldName:String, options:Object = null) : TypedArray
    • Sorts the elements in an array according to one or more fields in the array.
  • reverse : TypedArray
    • Reverses the array in place.
  • matchType (o:*) : Boolean
    • Verify if the passed-in object can be inserted in the
  • getType : Class
    • Return the current type allowed in the TypedArray
  • isTyped : Boolean
    • Returns true if this array perform a verification
  • toString : String
    • Returns the String representation of the object.
  • toArray : Array
    • Return a copy of the internal untyped Array TypedArray
  • size : uint
    • Return the size of the TypedArray
  • clone : TypedArray
    • Clone the typed array and return a new TypedArray
  • nextNameIndex (index:int) : int
  • nextName (index:int) : String
  • nextValue (index:int) : *

Constructor

TypedArray

public function TypedArray (
t:Class = null, args)

Create a new TypedArray instance.

Besides type the constructor works as the Arrayone, if only one additional arguments is passed to the function and
if its type is Number then this argument is used to set the length
of the TypedArray

Parameters:
t :
Type of elements in the array. The type is a Class instance witch is used with the is operator.
args:
You can use the array constructor in two different ways :
  • If only one int is passed to the function
    then it defines the number of elements in the array.
  • If several arguments is passed to the function those
    values are used to fill the array.
Throws:
  • {VISDOC_LINK_0}TypeError — If one or more of optionnal arguments are not of the
    same type than the array one.

Instance methods

clone

public function clone (

Clone the typed array and return a new TypedArray
Returns:
  • a copy of type Array.

concat

public function concat (
args) : TypedArray

Concatenates the elements specified in the parameters with
the elements in an array and creates a new array. If the
parameters specify an array, the elements of that array are concatenated.
Parameters:
args:
A value of any data type (such as numbers, elements, or strings)
to be concatenated in a new array. If you don't pass any values,
the new array is a duplicate of the original array.
Returns:
  • An array that contains the elements from this array followed by elements from the parameters.
Throws:
  • {VISDOC_LINK_0}TypeError — If one or more arguments are not of the same type that the array one.

filter

public function filter (
callback:Function, thisObject:* = null) : TypedArray

Executes a test function on each item in the array and constructs a new array
for all items that return true for the specified function. If an item returns
false, it is not included in the new array.

For this method, the second parameter, thisObject, must be null if the first
parameter, callback, is a method closure. Suppose you create a function in a
movie clip called me:


function myFunction()
{

}

Suppose you then use the filter() method on an array called myArray:

myArray.filter(myFunction, me);

Because myFunction is a member of the Timeline class, which cannot
be overridden by me, Flash Player will throw an exception.
You can avoid this runtime error by assigning the function to
a variable, as follows:

var foo:Function = myFunction() {;

};
myArray.filter(foo, me);

Parameters:
callback :
The function to run on each item in the array.
This function can contain a simple comparison
(for example, item < 20) or a more complex operation,
and is invoked with three arguments; the value of an item,
the index of an item, and the Array object:
function callback(item:*, index:int, array:Array):void;
thisObject:
An object to use as this for the function.
Returns:
  • A new array that contains all items from the original array that returned true.

getType

public function getType (
) : Class

Return the current type allowed in the TypedArray
Returns:
  • Class used to type checking.
Specified by:

isTyped

public function isTyped (
) : Boolean

Returns true if this array perform a verification
of the type of elements.
Returns:
  • true if this array perform a verification
    of the type of elements.
Specified by:

map

public function map (
callback:Function, thisObject:* = null) : TypedArray

Executes a function on each item in an array, and constructs a new array
of items corresponding to the results of the function on each item in the original array.

For this method, the second parameter, thisObject, must be null if the first parameter,
callback, is a method closure. Suppose you create a function in a movie clip called me:


function myFunction()
{

}

Suppose you then use the map() method on an array called myArray:

myArray.map(myFunction, me);

Because myFunction is a member of the Timeline class,
which cannot be overridden by me, Flash Player will throw
an exception. You can avoid this runtime error by assigning
the function to a variable, as follows:

var foo:Function = myFunction() {;

};
myArray.map(foo, me);

Parameters:
callback :
The function to run on each item in the array.
This function can contain a simple command (such as
changing the case of an array of strings) or a more complex
operation, and is invoked with three arguments; the value
of an item, the index of an item, and the Array object:
function callback(item:*, index:int, array:Array):void;
thisObject:
An object to use as this for the function
Returns:
  • A new array that contains the results of the function on each item in the original array.

matchType

public function matchType (
o:*) : Boolean

Verify if the passed-in object can be inserted in the
current TypedArray.
Parameters:
o:
Object to verify
Returns:
  • true if the object can be inserted in
    the TypedArray, either false.

nextName

override flash_proxy public function nextName (
index:int) : String

Overrides:
  • Proxy.nextName

nextNameIndex

override flash_proxy public function nextNameIndex (
index:int) : int

Overrides:
  • Proxy.nextNameIndex

nextValue

override flash_proxy public function nextValue (
index:int) : *

Overrides:
  • Proxy.nextValue

push

public function push (
args) : Number

Adds one or more elements to the end of an array and returns
the new length of the array.
Parameters:
args:
One or more values to append to the array.
Returns:
  • An integer representing the length of the new array.
Example:
  • The following code creates an empty TypedArray object
    letters and then populates the array with the elements
    a, b, and c using the push() method.
    var letters:TypedArray = new TypedArray( String );

    letters.push("a");
    letters.push("b");
    letters.push("c");

    trace( letters.toString() );
Throws:
  • {VISDOC_LINK_0}TypeError — If one or more arguments are not of the same type than
    the array one.

reverse

public function reverse (

Reverses the array in place.
Returns:
  • The new array
Example:
  • The following code creates a TypedArray object letters with
    elements a, b, and c. The order of the array elements is then reversed
    using the reverse() method to produce the array [c,b,a].

    var letters:TypedArray = new TypedArray( String, "a", "b", "c");
    trace(letters);
    letters.reverse();
    trace(letters);

size

public function size (
) : uint

Return the size of the TypedArray
Returns:
  • uint length of the array.

slice

public function slice (
startIndex:int, endIndex:int) : TypedArray

Returns a new array that consists of a range of elements from the original array,
without modifying the original array. The returned array includes the startIndex
element and all elements up to, but not including, the endIndex element.

If you don't pass any parameters, a duplicate of the original array is created.

Parameters:
startIndex:
A number specifying the index of the starting point for the slice.
If start is a negative number, the starting point begins at the end
of the array, where -1 is the last element.
endIndex :
A number specifying the index of the ending point for the slice.
If you omit this parameter, the slice includes all elements from
the starting point to the end of the array. If end is a negative
number, the ending point is specified from the end of the array,
where -1 is the last element.
Returns:
  • An array that consists of a range of elements from the original array.

sort

public function sort (
args) : TypedArray

Sorts the elements in an array. This method sorts according to Unicode values.
ASCII is a subset of Unicode.)

By default, Array.sort() works in the following way:

  • Sorting is case-sensitive (Z precedes a).
  • Sorting is ascending (a precedes b).
  • The array is modified to reflect the sort order; multiple elements
    that have identical sort fields are placed consecutively in the sorted
    array in no particular order.
  • All elements, regardless of data type, are sorted as if they were strings,
    so 100 precedes 99, because "1" is a lower string value than "9".

To sort an array by using settings that deviate from the default settings,
you can either use one of the sorting options described in the sortOptions
portion of the ...args parameter description, or you can create your own custom
function to do the sorting. If you create a custom function, you call the sort()
method, and use the name of your custom function as the first argument (compareFunction).

Parameters:
args:
The arguments specifying a comparison function and one or more values that
determine the behavior of the sort.

  • compareFunction - A comparison function used to determine the sorting order
    of elements in an array. This argument is optional. A comparison function
    should take two arguments to compare. Given the elements A and B, the
    result of compareFunction can have one of the following three values:
    • 1, if A should appear before B in the sorted sequence
    • 0, if A equals B
    • 1, if A should appear after B in the sorted sequence
  • sortOptions - One or more numbers or defined constants, separated by the | (bitwise OR) operator, that change the behavior of the sort from the default. This argument is optional. The following values are acceptable for sortOptions:
    • 1 or Array.CASEINSENSITIVE
    • 2 or Array.DESCENDING
    • 4 or Array.UNIQUESORT
    • 8 or Array.RETURNINDEXEDARRAY
    • 16 or Array.NUMERIC
    For more information, see the Array.sortOn() method.

Returns:
  • The return value depends on whether you pass any arguments,
    as described in the following list:
    • If you specify a value of 4 or Array.UNIQUESORT for the
      sortOptions argument of the ...args parameter and two or more
      elements being sorted have identical sort fields, Flash returns
      a value of 0 and does not modify the array.
    • If you specify a value of 8 or Array.RETURNINDEXEDARRAY
      for the sortOptions argument of the ...args parameter,
      Flash returns a sorted numeric array of the indices that reflects
      the results of the sort and does not modify the array.
    • Otherwise, Flash returns nothing and modifies the array to reflect the sort order.

sortOn

public function sortOn (
fieldName:String, options:Object = null) : TypedArray

Sorts the elements in an array according to one or more fields in the array.
The array should have the following characteristics:
  • The array is an indexed array, not an associative array.
  • Each element of the array holds an object with one or more properties.
  • All of the objects have at least one property in common, the values
    of which can be used to sort the array. Such a property is called a field.

If you pass multiple fieldName parameters, the first field represents
the primary sort field, the second represents the next sort field, and so on.
Flash sorts according to Unicode values. (ASCII is a subset of Unicode.)
If either of the elements being compared does not contain the field that
is specified in the fieldName parameter, the field is assumed to be set
to undefined, and the elements are placed consecutively in the sorted array
in no particular order.

By default, Array.sortOn() works in the following way:

  • Sorting is case-sensitive (Z precedes a).
  • Sorting is ascending (a precedes b).
  • The array is modified to reflect the sort order;
    multiple elements that have identical sort fields are
    placed consecutively in the sorted array in no particular order.
  • Numeric fields are sorted as if they were strings, so 100 precedes 99,
    because "1" is a lower string value than "9".

Flash Player 7 added the options parameter, which you can use
to override the default sort behavior. To sort a simple array
(for example, an array with only one field), or to specify a
sort order that the options parameter doesn't support, use Array.sort().

To pass multiple flags, separate them with the bitwise OR (|) operator:

my_array.sortOn(someFieldName, Array.DESCENDING | Array.NUMERIC);

Flash Player 8 added the ability to specify a different sorting option
for each field when you sort by more than one field. In Flash Player 8 and later,
the options parameter accepts an array of sort options such that each sort option
corresponds to a sort field in the fieldName parameter. The following
example sorts the primary sort field, a, using a descending sort;
the secondary sort field, b, using a numeric sort; and the tertiary sort field,
c, using a case-insensitive sort:

Array.sortOn (["a", "b", "c"], [Array.DESCENDING, Array.NUMERIC, Array.CASEINSENSITIVE]);

Parameters:
fieldName:
A string that identifies a field to be used as the sort value,
or an array in which the first element represents the primary
sort field, the second represents the secondary sort field, and so on.
options :
One or more numbers or names of defined constants, separated by the
bitwise OR (|) operator, that change the sorting behavior. The following
values are acceptable for the options parameter:
  • Array.CASEINSENSITIVE or 1
  • Array.DESCENDING or 2
  • Array.UNIQUESORT or 4
  • Array.RETURNINDEXEDARRAY or 8
  • Array.NUMERIC or 16
Returns:
  • The return value depends on whether you pass any parameters:
    • If you specify a value of 4 or Array.UNIQUESORT for the options parameter,
      and two or more elements being sorted have identical sort fields, a value of 0 is
      returned and the array is not modified.
    • If you specify a value of 8 or Array.RETURNINDEXEDARRAY for the options
      parameter, an array is returned that reflects the results of the sort and the
      array is not modified.
    • Otherwise, nothing is returned and the array is modified to reflect the sort order.

splice

public function splice (
startIndex:int, deleteCount:int, values) : TypedArray

Adds elements to and removes elements from an array.
This method modifies the array without making a copy.
Parameters:
startIndex :
An integer that specifies the index of
the element in the array where the insertion
or deletion begins. You can use a negative integer
to specify a position relative to the end of the array
(for example, -1 is the last element of the array).
deleteCount:
An integer that specifies the number of elements
to be deleted. This number includes the element specified
in the startIndex parameter. If you do not specify a value
for the deleteCount parameter, the method deletes all of
the values from the startIndex element to the last element
in the array. If the value is 0, no elements are deleted.
values :
An optional list of one or more comma-separated values,
or an array, to insert into the array at the position specified
in the startIndex parameter.
Returns:
  • An array containing the elements that were removed from the original array.
Throws:
  • {VISDOC_LINK_0}TypeError — If one or more additional arguments are not of the same type than
    the array one.

toArray

public function toArray (
) : Array

Return a copy of the internal untyped Array TypedArray
Returns:
  • a copy of type Array.

toString

public function toString (
) : String

Returns the String representation of the object.

unshift

public function unshift (
args) : Number

Adds one or more elements to the beginning of an array
and returns the new length of the array. The other elements
in the array are moved from their original position, i, to i+1.
Parameters:
args:
One or more numbers, elements, or variables
to be inserted at the beginning of the array.
Returns:
  • An integer representing the new length of the array.
Throws:
  • {VISDOC_LINK_0}TypeError — If one or more arguments are not of the same type than
    the array one.