Hello folks,
I’ve been trying to run a function from a string AS3 style supposed to substitute eval(), which is very easy, but there is a problem when running it from a text input box (I’m trying to create a program where users can enter variable names that can convert to functions):
Make sure you make a text input box in your FLA with the name of “runtxt”, and the value inside the text input box of “run” (without the quotes of course).
function run():void{
trace(“function run() runs”);
}
var runString:String = “run”;
thisrunString; // why does it work here but not when I grab the string from a text box below??
var runtxt1:String = runtxt.text.toString();
var newtxt1:String = new String("");
for(var i:int = 0; i<runtxt1.length; i++) {
//trace(runtxt1.charAt(i));
newtxt1 += runtxt1.charAt(i);
}
trace(runtxt1);
thisruntxt1; // does not work
thisnewtxt1; // even a brand new String with concatenation of the text input’s text does not work
The question is : Why does it NOT work when I grab the string from the textbox “runtxt” ?? I tried it without the charAt code for loop by just running thisruntxt1; and it does not work either for whatever reason.