Previously, in PBE Series: dynamically get list of public members, properties and methods of object or class, I noted that
SchemaGenerator.instance.generateSchema();
“dumps all classes and public info to a xml file”.
We’ll, I’ve used it now, and I must admit that was a lie ![]()
So here’s how you use it, and what it results in!
First, you need to establish a local connection, and then call generateSchema:
conn = new LocalConnection(); conn.client = this; conn.allowDomain('*'); try { conn.connect("_SchemaConnection"); } catch (error:ArgumentError) { trace("Can't connect to _SchemaConnection"); } SchemaGenerator.instance.generateSchema();
SchemaGenerator.instance.generateSchema will then call OnSchemaReceived in your class, so you need to add that. It takes two string arguments: type and data. Type is either “START”, “END”, “ERROR” or “TYPE”. Data is an XML description of the current processed class (internally it uses flash.utils.describeType), which you then can further interact with.
Here’s an example of how OnSchemaReceived could look like:
public function OnSchemaReceived(type:String, data:String):void { switch( type ) { case "START": break; case "END": break; case "ERROR": break; case "TYPE": { var myXML:XML = new XML(data); myXML.ignoreWhite = true; var xmlList:XMLList = myXML.child("factory"); //Check accessors: for each (var acc:XML in xmlList.accessor) { //DO SOMETHING. } //Check public variables: for each (var pVar:XML in xmlList.variable) { //DO SOMETHING. } } break; } }
That should help you getting started!
