Packagecom.daveoncode.util
Classpublic final class ObjectCollector

Provides a simple way to access objects references from anywhere by using id(s)


Example
// From anywhere you first create and register objects:

var collector:ObjectCollector = ObjectCollector.getInstance();
var myObj1:Button = new Button();

myObj1.width = 300;
myObj1.label = "my first button";
myObj1.id = "myFirstButton"; // id is mandatory, otherwise you'll get an error

var myObj2:TextInput = new TextInput();
myObj2.text = "hello world";
myObj2.id = "myTextField"; // id is mandatory, otherwise you'll get an error

collector.registerObject(myObj1);
collector.registerObject(myObj2);

// ...then in another (or the same) place you can get references to your desired objects.
// (this time by specifying the id)
// When you retrieve objects from the collector you should always cast (upcast!) them to the right type
// (Because objects are collected as generic Object classes)

var btn:Button = Button(ObjectCollector.getInstance().getObject("myFirstButton"));

// When/if you don't need these reference anymore, you can remove them by id:

ObjectCollector.getInstance().unregisterObject("myFirstButton");

// or all together:

ObjectCollector.getInstance().unregisterAll();



Public Methods
 MethodDefined by
  
ObjectCollector's constructor function
ObjectCollector
  
getAll():Array
Returns all references to registered objects
ObjectCollector
  
[static] Returns the current ObjectCollector's instance
ObjectCollector
  
getObject(id:String):Object
Returns a reference to an object registered with the specified id
ObjectCollector
  
registerObject(obj:Object):void
Adds an object's reference to ObjectCollector's collection
ObjectCollector
  
Removes all the references to registerd objects
ObjectCollector
  
unregisterObject(id:String):Boolean
Removes a reference to a previously registered object (specified by id)
ObjectCollector
Constructor detail
ObjectCollector()constructor
public function ObjectCollector()

ObjectCollector's constructor function

Method detail
getAll()method
public function getAll():Array

Returns all references to registered objects

Returns
Array — Array A (heterogeneous) collection of references to registered objects
getInstance()method 
public static function getInstance():ObjectCollector

Returns the current ObjectCollector's instance

Returns
ObjectCollector — ObjectCollector ObjectCollector's instance
getObject()method 
public function getObject(id:String):Object

Returns a reference to an object registered with the specified id

Parameters
id:StringString used as object identifier

Returns
Object — Object Object registered
registerObject()method 
public function registerObject(obj:Object):void

Adds an object's reference to ObjectCollector's collection

Parameters
obj:ObjectAny type of Object you need to get a reference to
unregisterAll()method 
public function unregisterAll():void

Removes all the references to registerd objects

unregisterObject()method 
public function unregisterObject(id:String):Boolean

Removes a reference to a previously registered object (specified by id)

Parameters
id:StringString used as object identifier

Returns
Boolean — Boolean True if the reference has been found and removed from ObjectCollector's collection, false otherwise (the reference with the specified id was never been registered)