Packageorg.flintparticles.common.utils
Classpublic class WeightedArray
InheritanceWeightedArray Inheritance flash.utils.Proxy

A WeightedArray is a collection of values that are weighted. When a random value is required fromn the collection, the value returned is randomly selkected based on the weightings.

Due to the nature of a WeightedArray, there are no facilities to push, unshift or splice items into the array. All items are added to the WeightedArray using the add method.

The array items can be accessed using standard Array access so the items in the WeightedArray can be looped through in the same manner as a standard Array.



Public Properties
 PropertyDefined by
  length : uint
[read-only] The number of items in the WeightedArray
WeightedArray
  totalWeights : Number
[read-only] The sum of the weights of all the values.
WeightedArray
Public Methods
 MethodDefined by
  
Then constructor function is used to create a WeightedArray
WeightedArray
  
add(value:*, weight:Number):uint
Adds a value to the WeightedArray.
WeightedArray
  
clear():void
Empties the WeightedArray.
WeightedArray
  
contains(value:*):Boolean
Indicates if the value is in the WeightedArray
WeightedArray
  
Returns a random value from the WeightedArray.
WeightedArray
  
remove(value:*):Boolean
Removes the value from the WeightedArray
WeightedArray
  
removeAt(index:uint):*
Removes the item at a particular index from the WeightedArray
WeightedArray
Protected Methods
 MethodDefined by
  
getProperty(name:*):*
Provides Array access to read values from the WeightedArray
WeightedArray
  
nextName(index:int):String
Used to allow access through a for each loop.
WeightedArray
  
nextNameIndex(index:int):int
Used to allow access through a for each loop.
WeightedArray
  
nextValue(index:int):*
Used to allow access through a for each loop.
WeightedArray
  
setProperty(name:*, value:*):void
Used to set the value of an existing member of the WeightedArray.
WeightedArray
Property detail
lengthproperty
length:uint  [read-only]

The number of items in the WeightedArray

Implementation
    public function get length():uint
totalWeightsproperty 
totalWeights:Number  [read-only]

The sum of the weights of all the values.

Implementation
    public function get totalWeights():Number
Constructor detail
WeightedArray()constructor
public function WeightedArray()

Then constructor function is used to create a WeightedArray

Method detail
add()method
public function add(value:*, weight:Number):uint

Adds a value to the WeightedArray.

Parameters
value:* — the value to add
 
weight:Number — the weighting to place on the item

Returns
uint — the length of the WeightedArray
clear()method 
public function clear():void

Empties the WeightedArray. After calling this method the WeightedArray contains no items.

contains()method 
public function contains(value:*):Boolean

Indicates if the value is in the WeightedArray

Parameters
value:* — The item to look for in the WeightedArray

Returns
Boolean — true if the item is in the WeightedArray, false if it is not.
getProperty()method 
flash_proxy override function getProperty(name:*):*

Provides Array access to read values from the WeightedArray

Parameters
name:*

Returns
*
getRandomValue()method 
public function getRandomValue():*

Returns a random value from the WeightedArray. The weighting of the values is used when selcting the random value, so items with a higher weighting are more likely to be seleted.

Returns
* — A randomly selected item from the array.
nextName()method 
flash_proxy override function nextName(index:int):String

Used to allow access through a for each loop.

Parameters
index:int

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

Used to allow access through a for each loop.

Parameters
index:int

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

Used to allow access through a for each loop.

Parameters
index:int

Returns
*
remove()method 
public function remove(value:*):Boolean

Removes the value from the WeightedArray

Parameters
value:* — The item to remove from the WeightedArray

Returns
Boolean — true if the item is removed, false if it doesn't exist in the WeightedArray
removeAt()method 
public function removeAt(index:uint):*

Removes the item at a particular index from the WeightedArray

Parameters
index:uint — the index in the WeightedArray of the item to be removed

Returns
* — the item that was removed form the WeightedArray
setProperty()method 
flash_proxy override function setProperty(name:*, value:*):void

Used to set the value of an existing member of the WeightedArray. This method cannot be used to set a new member of the WeightedArray since this new member won't have a weight setting.

Parameters
name:*
 
value:*