Flex/AS3 - calling a function dynamically using a String?

前端 未结 3 1898
不思量自难忘°
不思量自难忘° 2021-02-05 13:32

Is it possible to call a function in AS3 using a string value as the function name e.g.

var functionName:String = \"getDetails\";

var instance1:MyObject = new          


        
3条回答
  •  死守一世寂寞
    2021-02-05 14:22

    You may use function.apply() or function.call() methods instead in the case when you dont know whether object has such method for instance.

    var functionName:String = "getDetails";
    var instance1:MyObject = new MyObject();
    var function:Function = instance1[functionName]
    if (function)
        function.call(instance1, yourArguments)
    

提交回复
热议问题