If you're referring to dynamically evaluating and executing expressions by interpreting code from strings, ActionScript 3 does not support eval() as some languages do.
There are some bytecode generators such as the ActionScript 3 Eval Library and as3scriptinglib which accomplish similar real time interpretation of code.
As noted, you could leverage a function rest parameter:
public function myFunc(... args) {
for each (var arg:String in args) {
trace(arg);
}
}
Called as:
myFunc("para1");
myFunc("para1", "para2");
Or, use a Function object passing an array of parameters using apply(), called as:
var f:Function = myFunc;
f.apply(this, ["para1", "para2"]);
Or, pass parameters using call(), called as:
var f:Function = myFunc;
f.call(this, "para1", "para2");
Another approach would be creating a Domain Specific Language to be parsed; or, simply parsing the string value as ActionScript such as:
package {
public class DSL {
public static function parse(thisArg:*, statement:String) {
// get the function name
var fn:String = statement.substr(0, statement.indexOf('('));
// get parameters (between parenthesis)
var params:Array = statement.substring(statement.indexOf('(') + 1, statement.lastIndexOf(')')).split(',');
params.forEach(function(element:*, index:int, arr:Array):void {
arr[index] = this[element.replace(/^\s+|\s+$/g, '')];
}, thisArg);
// execute
var f:Function = thisArg[fn];
f.apply(thisArg, params);
}
}
}
As a demo, call DSL.parse() and pass a string referencing a function, and properties:
package {
public class Demo {
public var para1:String = "hello";
public var para2:String = "world";
public function myFunc(... args) {
for each (var arg:String in args) {
trace(arg);
}
}
public function Demo() {
DSL.parse(this, "myFunc(para1);");
DSL.parse(this, "myFunc(para1, para2);");
}
}
}
This would output:
hello
hello
world