Flex: given Class object, get the name of the class it represents

10,996

Solution 1

flash.utils::getQualifiedClassName is the function you are looking for ... ;)

greetz

back2dos

Solution 2

If you want to know all there is about a class, use describeType. Related, you might find useful getDefinition and getDefinitionByName.

describeType return all the details in an XML object. If you're looking just for the name, try something like:

trace(describeType(String).@name);

This is general actionscript. It has no dependency on the flex framework. Goodluck.

Solution 3

here is a simple as2 code I've done that allows you to get the base class and the current class as a string :

If current class is empty, this is a base class

public function ObjectContructor(){
  var _construct:String;
  var _instance:String;
  for(var s:String in _global){
    if(this.constructor == _global[s])_construct = s;
    if(this instanceof _global[s] && this.constructor != _global[s])_instance = s;
  }
  trace("base class : " +_construct);
  trace("Current class : " + _instance);
}
Share:
10,996
paleozogt
Author by

paleozogt

Software Developer for Maxar. #SOreadytohelp

Updated on June 04, 2022

Comments

  • paleozogt
    paleozogt almost 2 years

    In Flex, say I have a Class object. How do I get a string for the class it represents?

    e.g.:

    var clazz:Class= String;
    trace(clazz);  // this gives "[class String]" but what I want is "String"
    
  • paleozogt
    paleozogt almost 15 years
    As I said, clazz.toString() returns "[class String]"
  • paleozogt
    paleozogt almost 15 years
    getQualifiedClassName(clazz) returns "String". I expected it to return "Class"!
  • zenazn
    zenazn almost 15 years
    flash.utils::getDefinitionByName() takes a string and returns a Class.
  • Tom Auger
    Tom Auger about 13 years
    This works, but note that it is significantly slower than getQualifiedClassName()