我在AS3一个变种,我想在一个字符串的名字我想、我在、变种、在一

2023-09-08 15:27:48 作者:倦旅人.

例如:

public var myVar:Object;
// now I want to get the myVar string
// myVar is not instanced*
public var whatINeedIsThisVar:String = 'myVar';

感谢

推荐答案

有没有办法做到这一点,当你的工作在释放模式(即不debuuging的SWF)局部变量名不存在了。

There is no way to do that, and when you are working in release mode (i.e. not debuuging a swf) local variable name didn't exist anymore.

但如果它是一类的公共字段名,你可以使用的不如describeType 以找到该名称。

But if it's a public field name of a class you can use describeType to found the name.

package {
 import flash.utils.describeType;

 class Foo extends Sprite {
  public var bar:Object;

  function Foo(){
   super();
   // trace all public field name in this class
   for each (variable:XML in describeType(this).variable) {
    trace("field name : ", variable.@name);
   } 
  }
 }
}