ActionScript 3 ActionScript 3通过函数名称的字符串表示来调用函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 ActionScript 3通过函数名称的字符串表示来调用函数相关的知识,希望对你有一定的参考价值。

/**
 * ActionScript 3 Call a Function by String Representation of Function Name
 * 
 * This will allow you to execute a function if you only have the function name
 * as a string. The compiler won't catch any issues with this, so be careful with
 * it. However, it can save a lot of time and code if used correctly.
 *
 * The first argument to "apply" is the object that the function should apply to
 * The second argument is an Array object of arguments to pass to the function
 */
var functionName:String = "myFunction";
var containerObject:Object = myContainerObject;

if (containerObject.hasOwnProperty(functionName))
    containerObject[functionName].apply(null, [ args ]);
else
    trace("Cannot call function: " + functionName + " does not exist in " + containerObject.id);

以上是关于ActionScript 3 ActionScript 3通过函数名称的字符串表示来调用函数的主要内容,如果未能解决你的问题,请参考以下文章

在 JavaScript 和 ActionScript 之间共享数组引用

MXML 和用于移动设备的 ActionScript 之间的真正区别是啥?

ActionScript 3 使用ActionScript 3暂停框架

ActionScript 3 ActionScript 3延迟功能

ActionScript 3 ActionScript 3 SliceBitmap类

ActionScript 3 ActionScript 3中的XML循环