开发者

as3 function pointer

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"

This won't work, but can you see what I'm trying to do? It's kind of like a function pointer, or when you pass a function name into an event listener. Thanks.


Either do what Jacob suggested, or you can even just do:

// 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


What you need is:

var plan:Object = { theFunctionName: myFunction }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜