简体   繁体   English

如何在AS3中获取类的别名字符串?

[英]How do I get the alias string of a class in AS3?

var alias:String = 'models.User';
registerClassAlias(alias, models.User);

// If I have the alias, then
// I can get the class like this:
var klass:Class = flash.net.getClassByAlias(alias);

// How do I do the reverse
// (get the alias from the class)?
//
// I want to do this, but I can't find a 
// 'getAliasByClass' function.
alias = getAliasByClass(klass);

getQualifiedClassName should do the trick. getQualifiedClassName应该可以解决问题。

alias = flash.utils.getQualifiedClassName( klass );
// should return: "models::User"

You can pass it a class reference, or an instance of the class, either way. 您可以通过任何一种方式将其传递给类引用或类的实例。

As stated above you can call flash.utils.describeType() and use "reflection" on your Actionscript object's class to query attributes, properties, methods of the object. 如上所述,您可以调用flash.utils.describeType()并在Actionscript对象的类上使用“反射”来查询对象的属性,属性和方法。

For example the following code snippet for ObjectCodec.as seems to retrieve the alias attribute by using "@": 例如, ObjectCodec.as的以下代码片段似乎使用“ @”检索了别名属性:

override protected function encodeComplex(o:Object, b:IBinary, context:IContext=null):void
{
        var desc:XML = describeType(o);
        var classAlias:String = desc.@alias;
        //...
}

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

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