views:

1277

answers:

4

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"
A: 

Does this work?

trace(clazz.toString());
Jason Miesionczek
As I said, clazz.toString() returns "[class String]"
paleozogt
A: 

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.

George Profenza
+1  A: 

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

back2dos
getQualifiedClassName(clazz) returns "String". I expected it to return "Class"!
paleozogt
flash.utils::getDefinitionByName() takes a string and returns a Class.
zenazn
A: 

Hello,

if(clazz.hasProperty('className'))
{
     trace(clazz['className']);
}

Adrian, http://blog.timeister.com/

Adrian Pirvulescu
The class `Class` don't have the `hasProperty` function. Do you mean `hasOwnProperty`? And what is that `className` property?
unkiwii