开发者

I have a var in as3 and I want to get its name in a string

开发者 https://www.devze.com 2023-01-17 03:41 出处:网络
Example: public var my开发者_JAVA技巧Var:Object; // now I want to get the myVar string // myVar is not instanced*

Example:

public var my开发者_JAVA技巧Var:Object;
// now I want to get the myVar string
// myVar is not instanced*
public var whatINeedIsThisVar:String = 'myVar';

thanks


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.

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

精彩评论

暂无评论...
验证码 换一张
取 消