Flex introspection API: describeType(value:*):XML

I am playing with the mx.automation framework provided by Flex. For that I need to associate each control with it’s automation implementation. More on that on a subsequent blog entry. But it some case I need to find the super class of a class

Let’s take the following three classes:

class A {}
class B extends A {}
class Tab extends Button {}

Now we can create the following function:

import flash.utils.describeType;
private function superClass(clazz:Class):String {
    return describeType(clazz).factory.extendsClass[0].@type;
}

Let run the following code

trace("A super class:"+superClass(A));
trace("B super class:"+superClass(B));
trace("Tab super class:"+superClass(Tab));

And we get the following output:

A super class:Object
B super class:com.nouvelles_solutions::A
Tab super class:mx.controls::Button

Let me know if there is an easier way.

The build in describeType function takes a class as parameter and return an XML definition of a class. For example describeType(B) returns the following:

<type name="com.nouvelles_solutions::B" base="Class" isDynamic="true" isFinal="true" isStatic="true">
  <extendsClass type="Class"/>
  <extendsClass type="Object"/>
  <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>
  <factory type="com.nouvelles_solutions::B">
    <extendsClass type="com.nouvelles_solutions::A"/>
    <extendsClass type="Object"/>
    <method name="a" declaredBy="com.nouvelles_solutions::B" returnType="void">
      <parameter index="1" type="String" optional="false"/>
    </method>
  </factory>
</type>

Pretty cool.

Posted by Daniel Wanja Sat, 24 Feb 2007 04:11:00 GMT


Comments

  1. jrevel over 1 year later:

    I played a lot also with describeType, and I finished by creating a tool dedicated to live code inspection for Flex.
    It is named KapInspect, and it may be usefull for you.

    You may find it here: http://lab.kapit.fr/

    Hope this helps