Since I don't have or want your full code, I'll just give you this. It's everything you should ever need to do with using functions as variables and parameters. For the parameters, there is a default function, and it can pass an unlimited number of parameters along with it. You can adjust this in ways to suit your situation.
function showString(cString:String = "Default string"):void
{
trace(cString);
}
function showSum(... nums):void
{
var i:int;
var cSum:Number = 0;
if (String(Number(nums))=="NaN"
&& nums.length==1)
{
/* nums is a 2D array, which occurs if the function was called by callFunctionWithParameters with 2 or more parameters
Would also occur if this happened to be called with an array as the parameter */
for(i=0; i<nums[0].length; i++)
{
cSum += nums[0][i];
}
} else
{
for(i=0; i<nums.length; i++)
{
cSum += nums[i];
}
}
trace(cSum);
}
function callFunctionWithParameters(cFunction:Function=null, ... args):void
{
if (cFunction == null)
{
cFunction = showString;
}
if (args[0] == null)
{
cFunction();
} else
{
cFunction(args);
}
}
function callSimpleFunction(cFunction:Function=null):void
{
if (cFunction == null)
{
cFunction = showString;
}
cFunction();
}
var tFunc:Function = showSum;
showSum(2);
showSum(2, 3);
tFunc();
trace("---")
callSimpleFunction();
callSimpleFunction(showString);
callFunctionWithParameters(showString, "nom nom");
trace("---");
callFunctionWithParameters();
callFunctionWithParameters(tFunc);
callFunctionWithParameters(tFunc, 19);
callFunctionWithParameters(tFunc, 19, 3);
That outputs the following:
2
5
0
---
Default string
Default string
nom nom
---
Default string
0
19
22
I trust you can figure it out. I can answer any specific questions about it.