Is there a possibility to extract variable name from string and using it as variable
var myvar:String = "flash";
var flash:Number = 10;
trace( myvar as variable );
something like that
Variable name as Strings can be done like so:
this["myvar"] = "flash";
Notes:
ReferenceError
if the property has not been previously defined AND the this
refers to an object which is not dynamic
.this
with the instance name of an object you want to use a property from, e.g. mySprite["x"]
.this["addChild"](mySprite);
You can use it as a property of an object.
public dynamic class MyClass {
function MyClass(propName:String, propValue:*) {
this[propName] = propValue;
}
}
or
var myvar:String = "flash";
var o : Object = {};
o[myvar] = 10;
trace(o.flash); //10
If you don't know what property name is going to be, then you should use dynamic
class (Object
is dynamic
by default)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With