any way of doing this is as3?
for example, if I have a var dog:String
, how can I get "dog" out of that variable?
Looking into reflection to do this, but there's got to be an easier way
-- A
any way of doing this is as3?
for example, if I have a var dog:String
, how can I get "dog" out of that variable?
Looking into reflection to do this, but there's got to be an easier way
-- A
Sounds like you don't want to "get" the string representation of a variable name, but rather set the variable based on a string.
To set a variable that you have its name as a string you can do this:
In your example I don't think there is a way to retrieve "dog" as a String.
However, if
dog
is a property of adynamic
Object, then you could use a function like this:This function can work in a scenario like this:
Hope this helps.
First of all if it's an instance of a custom class, you can override the
toString()
method.If it's a property of the class, you can use this method — https://stackoverflow.com/posts/3781635/revisions
If it's a local variable, there is no way to get that name.