views:

42

answers:

1

Example:

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

thanks

A: 

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);
   } 
  }
 }
}
Patrick
yes it's a public var in a class. is a skinPart.But I heard that is heavy to rely on describeType, right?Now I have found the .id but only works when instanced
Totty
@Totty If you can specify a little bit on what you want achieve, maybe there is a solution.
Patrick
"when you are working in release mode, local variable name didn't exist anymore". This is somewhat true, except there must be a lookup table to the variable names somewhere because you can access variables through string like so: this["bar"]. This does not mean YOU have access to the names though
TandemAdam
@TandemAdam, no LOCAL VARIABLE are just compiled as an integer index representing the position of the register holding the variable, but as i said you can access public CLASS MEMBER with describeType for example. Your this["bar"] is just accessing such a field.
Patrick
ok, thanks everybody. i have to try another way around. thanks anyway ;) how to close this question?
Totty