Packagecom.bourre.collection
Classpublic final dynamic class TypedArray
InheritanceTypedArray Inheritance flash.utils.Proxy
ImplementsTypedContainer

Player version: Flash Player 9.0
Language version: ActionScript 3.0

TypedArray work the same way than a classical Array but all elements in a TypedArray have to be of the same type.

The type of array's elements is set at creation, then you cannot change it after. Every time you try to insert data in the array the type of the element is checked, and an error is thrown if the type doesn't match the TypedArray one.

The TypedArray is final, you cannot extend it.


Example
Using a TypedArray directly
var a : TypedArray = new TypedArray ( Number );
  a[ 0 ] = 20; // no error
  a[ 1 ] = "20"; // throw an error
  



Public Methods
 MethodDefined by
  
TypedArray(t:Class = null, ... args)
Create a new TypedArray instance.
TypedArray
  
Clone the typed array and return a new TypedArray
TypedArray
  
concat(... args):TypedArray
Concatenates the elements specified in the parameters with the elements in an array and creates a new array.
TypedArray
  
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.
TypedArray
  
getType():Class
Return the current type allowed in the TypedArray
TypedArray
  
isTyped():Boolean
Returns true if this array perform a verification of the type of elements.
TypedArray
  
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.
TypedArray
  
matchType(o:*):Boolean
Verify if the passed-in object can be inserted in the current TypedArray.
TypedArray
  
push(... args):Number
Adds one or more elements to the end of an array and returns the new length of the array.
TypedArray
  
Reverses the array in place.
TypedArray
  
size():uint
Return the size of the TypedArray
TypedArray
  
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.
TypedArray
  
sort(... args):TypedArray
Sorts the elements in an array.
TypedArray
  
sortOn(fieldName:String, options:Object = null):TypedArray
Sorts the elements in an array according to one or more fields in the array.
TypedArray
  
splice(startIndex:int, deleteCount:int, ... values):TypedArray
Adds elements to and removes elements from an array.
TypedArray
  
toArray():Array
Return a copy of the internal untyped Array TypedArray
TypedArray
  
toString():String
Returns the String representation of the object.
TypedArray
  
unshift(... args):Number
Adds one or more elements to the beginning of an array and returns the new length of the array.
TypedArray
Protected Methods
 MethodDefined by
  
nextName(index:int):String
TypedArray
  
nextNameIndex(index:int):int
TypedArray
  
nextValue(index:int):*
TypedArray
Constructor detail
TypedArray()constructor
public function TypedArray(t:Class = null, ... args)

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Create a new TypedArray instance.

Besides type the constructor works as the Array one, 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:Class (default = null) — t Type of elements in the array. The type is a Class instance witch is used with the is operator.
 
... args — 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
TypeError — If one or more of optionnal arguments are not of the same type than the array one.
Method detail
clone()method
public function clone():TypedArray

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Clone the typed array and return a new TypedArray

Returns
TypedArray — a copy of type Array.
concat()method 
public function concat(... args):TypedArray

Player version: Flash Player 9.0
Language version: ActionScript 3.0

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
TypedArray — An array that contains the elements from this array followed by elements from the parameters.

Throws
TypeError — If one or more arguments are not of the same type that the array one.
filter()method 
public function filter(callback:Function, thisObject:* = null):TypedArray

Player version: Flash Player 9.0
Language version: ActionScript 3.0

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()
      {
       //your code here
      }

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() {
           //your code here
      };
      myArray.filter(foo, me);

Parameters
callback:Function — 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:* (default = null) — thisObject An object to use as this for the function.

Returns
TypedArray — A new array that contains all items from the original array that returned true.
getType()method 
public function getType():Class

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Return the current type allowed in the TypedArray

Returns
ClassClass used to type checking.
isTyped()method 
public function isTyped():Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns true if this array perform a verification of the type of elements.

Returns
Booleantrue if this array perform a verification of the type of elements.
map()method 
public function map(callback:Function, thisObject:* = null):TypedArray

Player version: Flash Player 9.0
Language version: ActionScript 3.0

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()
      {
       //your code here
      }

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() {
           //your code here
      };
      myArray.map(foo, me);

Parameters
callback:Function — 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:* (default = null) — thisObject An object to use as this for the function

Returns
TypedArray — A new array that contains the results of the function on each item in the original array.
matchType()method 
public function matchType(o:*):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Verify if the passed-in object can be inserted in the current TypedArray.

Parameters
o:* — Object to verify

Returns
Booleantrue if the object can be inserted in the TypedArray, either false.
nextName()method 
flash_proxy override function nextName(index:int):String

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Parameters
index:int

Returns
String
nextNameIndex()method 
flash_proxy override function nextNameIndex(index:int):int

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Parameters
index:int

Returns
int
nextValue()method 
flash_proxy override function nextValue(index:int):*

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Parameters
index:int

Returns
*
push()method 
public function push(... args):Number

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Adds one or more elements to the end of an array and returns the new length of the array.

Parameters
... args — args One or more values to append to the array.

Returns
Number — An integer representing the length of the new array.

Throws
TypeError — If one or more arguments are not of the same type than the array one.

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() ); // a,b,c

reverse()method 
public function reverse():TypedArray

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Reverses the array in place.

Returns
TypedArray — 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); // com.bourre.collection.TypedArray [a,b,c]
      letters.reverse();
      trace(letters); // com.bourre.collection.TypedArray [c,b,a]
      

size()method 
public function size():uint

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Return the size of the TypedArray

Returns
uintuint length of the array.
slice()method 
public function slice(startIndex:int, endIndex:int):TypedArray

Player version: Flash Player 9.0
Language version: ActionScript 3.0

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:int — 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:int — 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
TypedArray — An array that consists of a range of elements from the original array.
sort()method 
public function sort(... args):TypedArray

Player version: Flash Player 9.0
Language version: ActionScript 3.0

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:

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
TypedArray — 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()method 
public function sortOn(fieldName:String, options:Object = null):TypedArray

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Sorts the elements in an array according to one or more fields in the array. The array should have the following characteristics:

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:

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:String — 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:Object (default = null) — 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
TypedArray — 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()method 
public function splice(startIndex:int, deleteCount:int, ... values):TypedArray

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Adds elements to and removes elements from an array. This method modifies the array without making a copy.

Parameters
startIndex:int — 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:int — 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
TypedArray — An array containing the elements that were removed from the original array.

Throws
TypeError — If one or more additional arguments are not of the same type than the array one.
toArray()method 
public function toArray():Array

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Return a copy of the internal untyped Array TypedArray

Returns
Array — a copy of type Array.
toString()method 
public function toString():String

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns the String representation of the object.

Returns
String
unshift()method 
public function unshift(... args):Number

Player version: Flash Player 9.0
Language version: ActionScript 3.0

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
Number — An integer representing the new length of the array.

Throws
TypeError — If one or more arguments are not of the same type than the array one.