| Package | org.flintparticles.common.utils |
| Class | public class WeightedArray |
| Inheritance | WeightedArray flash.utils.Proxy |
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.
| Property | Defined 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 | ||
| Method | Defined 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 | ||
getRandomValue():*
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 | ||
| Method | Defined By | ||
|---|---|---|---|
getProperty(name:*):* [override]
Provides Array access to read values from the WeightedArray
| WeightedArray | ||
nextName(index:int):String [override]
Used to allow access through a for each loop. | WeightedArray | ||
nextNameIndex(index:int):int [override]
Used to allow access through a for each loop. | WeightedArray | ||
nextValue(index:int):* [override]
Used to allow access through a for each loop. | WeightedArray | ||
setProperty(name:*, value:*):void [override]
Used to set the value of an existing member of the WeightedArray. | WeightedArray | ||
| length | property |
length:uint [read-only] The number of items in the WeightedArray
public function get length():uint| totalWeights | property |
totalWeights:Number [read-only] The sum of the weights of all the values.
public function get totalWeights():Number| WeightedArray | () | Constructor |
public function WeightedArray()Then constructor function is used to create a WeightedArray
| add | () | method |
public function add(value:*, weight:Number):uintAdds a value to the WeightedArray.
Parameters
value:* — the value to add
| |
weight:Number — the weighting to place on the item
|
uint — the length of the WeightedArray
|
| clear | () | method |
public function clear():voidEmpties the WeightedArray. After calling this method the WeightedArray contains no items.
| contains | () | method |
public function contains(value:*):BooleanIndicates if the value is in the WeightedArray
Parameters
value:* — The item to look for in the WeightedArray
|
Boolean — true if the item is in the WeightedArray, false if it is not.
|
| getProperty | () | method |
override flash_proxy function getProperty(name:*):*Provides Array access to read values from the WeightedArray
Parameters
name:* |
* |
| 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 |
override flash_proxy function nextName(index:int):StringUsed to allow access through a for each loop.
Parameters
index:int |
String |
| nextNameIndex | () | method |
override flash_proxy function nextNameIndex(index:int):intUsed to allow access through a for each loop.
Parameters
index:int |
int |
| nextValue | () | method |
override flash_proxy function nextValue(index:int):*Used to allow access through a for each loop.
Parameters
index:int |
* |
| remove | () | method |
public function remove(value:*):BooleanRemoves the value from the WeightedArray
Parameters
value:* — The item to remove from the WeightedArray
|
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
|
* — the item that was removed form the WeightedArray
|
| setProperty | () | method |
override flash_proxy function setProperty(name:*, value:*):voidUsed 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:* |