Class com.bumpslide.util.ObjectUtil

com.bumpslide.util.ObjectUtil

Description

ObjectUtil contains fundamental methods to efficiently and easily work with any type of object. David stole this from AS2LIB, and removed all the dependencies and crap.

Field Index

TYPE_BOOLEAN, TYPE_FUNCTION, TYPE_MOVIECLIP, TYPE_NULL, TYPE_NUMBER, TYPE_OBJECT, TYPE_STRING, TYPE_UNDEFINED

Method Index

clone(), compare(), compareTypeOf(), getKey(), getNextHashKey(), initHashKeys(), isExplicitInstanceOf(), isInstanceOf(), isPrimitiveType(), isTypeOf()

Field Detail

TYPE_STRING

static public TYPE_STRING:String
Constant for objects of type string.

TYPE_NUMBER

static public TYPE_NUMBER:String
Constant for objects for type number.

TYPE_OBJECT

static public TYPE_OBJECT:String
Constant for objects of type object.

TYPE_BOOLEAN

static public TYPE_BOOLEAN:String
Constant for objects of type boolean.

TYPE_MOVIECLIP

static public TYPE_MOVIECLIP:String
Constant for objects of type movieclip.

TYPE_FUNCTION

static public TYPE_FUNCTION:String
Constant for objects of type function.

TYPE_UNDEFINED

static public TYPE_UNDEFINED:String
Constant for the value undefined.

TYPE_NULL

static public TYPE_NULL:String
Constant for the value null.

Method Detail

compareTypeOf

static public function compareTypeOf(firstObject, secondObject):Boolean

Compares the results of an execution of the typeof method applied to both passed-in objects.

Parameters

firstObjectthe first object of the comparison
secondObjectthe second object of the comparison

Return

true if the execution of the typeof method returns the same else false

isPrimitiveType

static public function isPrimitiveType(object):Boolean

Checks if the passed-in object is a primitive type.

Primitive types are strings, numbers and booleans that are not created via the new operator. For example "myString", 3 and true are primitive types, but new String("myString"), new Number(3) and new Boolean(true) are not.

Parameters

objectthe object to check whether it is a prmitive type

Return

true if object is a primitive type else false

isTypeOf

static public function isTypeOf(object, type:String):Boolean

Checks if the result of an execution of the typeof method on the passed-in object matches the passed-in type.

All possible types are available as constants.

Parameters

objectthe object whose type to check
typethe string representation of the type

Return

true if the object is of the given type

isInstanceOf

static public function isInstanceOf(object, type:Function):Boolean

Checks if the passed-in object is an instance of the passed-in type.

If the passed-in type is Object, true will always be returned, because every object is an instance of Object, even null and undefined.

Parameters

objectthe object to check
typethe type to check whether the object is an instance of

Return

true if the passed-in object is an instance of the given type else false

isExplicitInstanceOf

static public function isExplicitInstanceOf(object, clazz:Function):Boolean

Checks if the passed-in object is an explicit instance of the passed-in clazz.

That means that true will only be returned if the object was instantiated directly from the given clazz.

Parameters

objectthe object to check whether it is an explicit instance of clazz
clazzthe class to use as the basis for the check

Return

true if the object is an explicit instance of clazz else false

compare

static public function compare(obj1, obj2):Boolean

Checks if two passed-in parameters are equal.

It uses different strategies by the first passed-in obj1.

  • If obj1 is a primitive it compares it with == operator.
  • If obj1 implements Comparable it calls compare() to compare both passed-in parameters
  • Any different case compares the structure of both objects.

It compares complex objects (that do not implement Comparable) only if they are instances of the same class. A different class (even if its only a extended class) will be handled as not equal.

It compares complex objects recursivly. It handles back references in a proper way.

Parameters

obj1object to be compared
obj2object to compare with passed-in obj1

Return

true if both parameters are equal

clone

static function clone(obj:Object)

getKey

static public function getKey(o):Number

Returns passed-in o object key.

Return

Number

getNextHashKey

static public function getNextHashKey():Number

static method called from within __KEY getter in objects no need to ever call this directly. please ignore.

initHashKeys

static public function initHashKeys(o):Boolean