private function myFunction(numIn:Number){
trace ("numIn " + numIn);
}
var plan:Object = { "theFunctionName": "myFunction" }
// now use the function
plan.theFunctionName(5);
// should trace out: "numIn 5"
这不起作用,但你能看到我想要做什么吗?它有点像函数指针,或者当您将函数名称传递给事件侦听器时。谢谢。
答案 0 :(得分:16)
要么做雅各布建议,要么你甚至可以做:
// Your function.
function myFunction(numIn:Number):void
{
trace("numIn " + numIn);
}
// Assign "myFunction" to the property "callback" of type "Function".
var callback:Function = myFunction;
// Call "myFunction" via "callback".
callback(5); // numIn 5
答案 1 :(得分:4)
您需要的是:
var plan:Object = { theFunctionName: myFunction }