Global data storage: Registry.as

Singleton classes can be accessible from anywhere anytime. It’s like the ”good” old _global. It behaves like a static class, but it is persistent so it can store data that can be retrieved from any class, object or component.

I also added some static functions to get around calling the usual ”getInstance()” everytime the class was needed.

The Registry class is a global data storage accessible with methods ”get” and ”add”.

Example:


/**
 * Add data to the Registry
 * Registry.add(ID,VALUE);
 *
 * @param id An unique identifier for the data
 * @param data The data to store
 *
 * @return nothing
 */

Registry.add("test",d);

/**
 * Get data from the Registry
 * Registry.get(ID);
 *
 *
 * @param id The unique identifier of the data
 *
 * @return The data
 *
 */

trace(Registry.get("test"));

Download demo and classes.

Kommentoi