| 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:*):*
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 | ||
| length | property |
length:uint [read-only]The number of items in the WeightedArray
Implementation public function get length():uint
| totalWeights | property |
totalWeights:Number [read-only]The sum of the weights of all the values.
Implementation 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.
Parametersvalue:* — 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
Parametersvalue:* — The item to look for in the WeightedArray
|
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
Parametersname:* |
* |
| 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):StringUsed to allow access through a for each loop.
Parametersindex:int |
String |
| nextNameIndex | () | method |
flash_proxy override function nextNameIndex(index:int):intUsed to allow access through a for each loop.
Parametersindex:int |
int |
| nextValue | () | method |
flash_proxy override function nextValue(index:int):*Used to allow access through a for each loop.
Parametersindex:int |
* |
| remove | () | method |
public function remove(value:*):BooleanRemoves the value from the WeightedArray
Parametersvalue:* — 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
Parametersindex:uint — the index in the WeightedArray of the item to be removed
|
* — the item that was removed form the WeightedArray
|
| setProperty | () | method |
flash_proxy override 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.
Parametersname:* |
|
value:* |