Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 912
dt1000 Avatar asked Dec 01 '22 08:12

dt1000


2 Answers

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
like image 186
Marty Avatar answered Dec 05 '22 08:12

Marty


What you need is:

var plan:Object = { theFunctionName: myFunction }
like image 37
Jacob Eggers Avatar answered Dec 05 '22 07:12

Jacob Eggers