Packageimpression.utilities
Classpublic class TypeUtils
InheritanceTypeUtils Inheritance Object

The TypeUtils class contains type-specific helper methods.



Public Methods
 MethodDefined By
  
getBoolean(value:*):Boolean
[static] Returns the Boolean representation of value.
TypeUtils
  
getNumber(value:*, defaultValue:Number):Number
[static] Returns the Number representation of value.
TypeUtils
  
getString(value:*):String
[static] Returns the String representation of value.
TypeUtils
  
sequentialArray(length:uint, start:Number = 0):Array
[static] Returns an ordered array of numbers, where each value in the array is the array index plus start.
TypeUtils
  
shuffleArray(items:Array, forceNewOrder:Boolean = false):void
[static] Randomizes the order of the items in the array.
TypeUtils
Method Detail
getBoolean()method
public static function getBoolean(value:*):Boolean

Returns the Boolean representation of value.

Parameters

value:* — Expression identifying the item to return the Boolean representation of. value can be one of the following types:
  • Null. The method returns false.
  • String. The method returns false if value is one of the following strings:
    • false
    • off
    • 0
    • The empty string ("")
    For all other strings, the method returns true.
  • Number (including int and uint). The method returns false if the value is 0, otherwise, the method returns true.
  • [other types]. The method returns the result of casting value to a Boolean.

Returns
Boolean — The Boolean representation of value.
getNumber()method 
public static function getNumber(value:*, defaultValue:Number):Number

Returns the Number representation of value.

This method attempts to return the result of casting value to a Number. If value is null, the casted result is NaN, or an error occurs, the method returns defaultValue.

Parameters

value:* — Expression identifying the item to return the Number representation of.
 
defaultValue:Number — The Number to return if a valid cast cannot be made.

Returns
Number — The Number representation of value, or defaultValue.
getString()method 
public static function getString(value:*):String

Returns the String representation of value.

Parameters

value:* — Expression identifying the item to return the String representation of. value can be one of the following types:
  • Null. The method returns the empty string ("").
  • [other types]. The method returns the result of casting value to a String.

Returns
String — The String representation of value.
sequentialArray()method 
public static function sequentialArray(length:uint, start:Number = 0):Array

Returns an ordered array of numbers, where each value in the array is the array index plus start.

Parameters

length:uint — The length of the returned array.
 
start:Number (default = 0) — The value of the first element in the returned array.

Returns
Array — An Array of numbers, ordered from start to start + [length - 1].
shuffleArray()method 
public static function shuffleArray(items:Array, forceNewOrder:Boolean = false):void

Randomizes the order of the items in the array.

This method uses the Fisher-Yates algorithm to shuffle the items.

Parameters

items:Array — The array to shuffle.
 
forceNewOrder:Boolean (default = false) — Optional parameter indicating how randomization should occur. If this value is true, the method makes a shallow copy of the array, shuffles the original, and compares the shuffled result to the shallow copy. If the two arrays match, the first item in the array is swapped with another item, ensuring that the array is not in the original order.