Let’s say that I have a class Foo:
public class Foo { public static var bar:String = 'test'; }
How can I reference bar at runtime using the string ‘Foo’ or/and and instance of Foo and the string ‘bar’?
I.e.
var x:Object = new Foo(); ... x['bar']
…doesn’t work, debug mode in IntelliJ got my hopesup as bar gets listed as a property.
Update:
Note that at the ‘point of action’ I don’t know anything about foo in compile time. I need to resolve Foo.bar through the strings ‘Foo’ and ‘bar’.
Of put differently, as flex don’t have eval how can I accomplishe the same as eval(‘Foo.bar’)?
It’s a static variable, so you won’t be able to access it using an instance of foo; it’s accessed statically, using ClassName.variableName notation, like so:
trace(Foo.bar);
// yields: ‘test’
As well, because you’ve declared both Foo and bar public, you should be able to access Foo.bar that way from anywhere in your application.
Update: Ah, I see what you’re asking. You can use flash.utils.Summary.getDefinitionByName():
… the latter thanks to Jeremy’s answer, which was new to me. 🙂