ClassRegistry
DDW Framework Library

ClassRegistry is a utility that facilitates normal object-oriented syntax usage, allowing both C# and Java syntax. Features include setting inheritance, implementing interfaces, creating namespaces, global aliasing and allows defining things in any order.

For a list of members of this class, see ClassRegistry Members.

Object
    DDW.Actionscript.ClassRegistry

class ClassRegistry

Size

2k compressed
Note: be sure to remove the RegistryTools class (used for validating and debugging only) from the final swf.

Remarks

The only significant public methods, DefineClass and DefineInterface, are mapped to the _global namespace and automatically find the ClassRegistry instance. Unless writing your own extensions or analysis tools, these are probably the only two ways you will interact with this class.

You do not create instances of the registry directly, rather you must obtain the singleton instance from the static ClassRegistry.Instance() method. With this instance you can Lookup classes using string names, as well as DefineClass and DefineInterface using C# or Java syntax. Classes can be defined in any order, existing classes can even be picked up off a timeline. All classes are stored in the ClassTable, and they have a Reflection property that contains meta information about the class such as the name, the base class, derived classes etc. (see ClassInfo for details on the meta information). A reference to the ClassTable is also available as a global keyword. The RegistryTools class provides design time debugging support, as well as the ability to Validate all class definitions and insure all interfaces have been implemented.

Example

// Define interface
DefineInterface("Interface.IFace.IFace0");
// The namespace was automatically created, defaults to having global alias.
IFace0=function(){}
IFace0.prototype.A = null;
IFace0.prototype.B = null;

// Notice interfaces can also define properties and methods
// that will get picked up by derived classes. In this situation,
// the Interface must be defined before the derived class.
DefineInterface("Interface.IFace.IFace1");
IFace1=function(){}
IFace1.prototype.C = "IMethC";
IFace1.prototype.D = "IMethD";

DefineInterface("Interface.IFace.IFace2");
IFace2=function(){}
IFace2.prototype.E = null;
IFace2.prototype.F = null;

// Define a class using C# syntax. The second parameter specifies
// whether the class will be given a _global root alias, which it won't
// in this case, so the class must always be referenced using its full namespace.
// Also notice these can be defined out of order - ClassC inherits from ClassB
// which is not yet defined.
DefineClass("Sys.Test.ClassC : ClassB", false);
Sys.Test.ClassC=function(){super();trace("Made C");}
Sys.Test.ClassC.prototype.methA=function(){return "MethA";}

// Though it isn't recommended, you can define your class function first
// may be useful when picking up classes from movieclips (yikes!).
ClassA=function(){super();trace("Made A");}
ClassA.prototype.prop = "prop from classA";
ClassA.prototype.meth = function(){};
DefineClass("Sys.Test.ClassA : IFace0");

// Java syntax is fine if you are more comfortable with it.
// You can of course implement multiple interfaces.
// Notice classes do not need to be in a namespace (though they should be!),
// and extra whitespace is automatically stripped out
DefineClass("ClassB Extends ClassA Implements IFace1, IFace2 ");
ClassB=function(){super();trace("Made B");}

// Insure all classes are defined, and all interfaces are implemented
// (which they aren't in this example). This method is from the RegistryTools class.
Validate();

Requirements

This class depends on ClassInfo being available (included in ClassRegistry.as file), and you must load RegistryTools.as in order to debug/validate your code. All tracing / debugging / display / documentation code you wish to add that the runtime file does not depend on, should go in RegistryTools.as (or a subclass of it if you wish). Be sure to comment out #include RegistryTools.as before your final export, or it will add unnecessary size to your project. This class does not depend on any parent classes being loaded, and creates its own namespace.

See Also

DDW.Actionscript Namespace, RegistryTools, ClassInfo

Download

You can download the RegistryTools package here.

Note: You are free to use this code in your own projects, however you may not distribute it, nor use it as part of other tools, frameworks, or any other code generation software without permission.

Comment

Submit Comment | View Comments (there are currently <TODO> comments for this page)

 

© 2002 Debreuil Digital Works. All rights reserved.