简体   繁体   English

Flex:给定Class对象,获取它所代表的类的名称

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

In Flex, say I have a Class object. 在Flex中,假设我有一个Class对象。 How do I get a string for the class it represents? 如何获取它所代表的类的字符串?

eg: 例如:

var clazz:Class= String;
trace(clazz);  // this gives "[class String]" but what I want is "String"

flash.utils::getQualifiedClassName is the function you are looking for ... ;) flash.utils::getQualifiedClassName是你要找的函数......;)

greetz 格尔茨

back2dos back2dos

If you want to know all there is about a class, use describeType . 如果你想知道关于一个类的所有内容,请使用describeType Related, you might find useful getDefinition and getDefinitionByName . 相关的,您可能会发现有用的getDefinitiongetDefinitionByName

describeType return all the details in an XML object. describeType返回XML对象中的所有详细信息。 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. 它不依赖于flex框架。 Goodluck. 祝好运。

here is a simple as2 code I've done that allows you to get the base class and the current class as a string : 这里有一个简单的as2代码,它允许您将基类和当前类作为字符串获取:

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);
}

这有用吗?

trace(clazz.toString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM