Flex/AS3 - 使用String动态调用函数?

Dre*_*nai 14 apache-flex actionscript-3

是否可以使用字符串值作为函数名称来调用AS3中的函数,例如

var functionName:String = "getDetails";

var instance1:MyObject = new MyObject();

instance1.functionName(); // I know this is so wrong, but it gets the point accross:)
Run Code Online (Sandbox Code Playgroud)

UPDATE

@Taskinoor在访问函数时的答案是正确的:

instance1[functionName]();
Run Code Online (Sandbox Code Playgroud)

要访问我们将使用的属性:

instance1[propertyName]
Run Code Online (Sandbox Code Playgroud)

tas*_*oor 24

instance1[functionName]();

检查一下这些细节.

  • 只是捎带这一点,你可以问例如,如果它使用`in`关键字的函数或VAR:`如果(在INSTANCE1 functionName)` (7认同)