0
votes

I read this : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Function.html But that does not exactly correspond to what I want to do, and I can't find the right solution. However my question is not so complicated.

Here is the situation :

mains.as contains a functionA(strParam:String)

onlineClass.as contains a functionB working like this :

private static functionB (fnParam:Function):void //my fnParam is functionA
{
    var strParam:String = getSomeStringResult(); 
    //I have a result from a function

    fnParam.call(strParam); 
    //I want to execute functionA with strParam as parameter
}

But I don't understand what I have to do with call parameters. I tried :

fnParam.call(null, strParam);

But it returns an error : [Fault] exception, information=TypeError: Error #1009: Impossible to access a property or a method of a null object's reference

I am sure the answer already exists somewhere but a search with "function" and "call" leads nowhere.

Thank you for the help.

2
If the only argument for functionB is fnParam (and you're passing functionA), then where are you getting strParam from? - Marcela
strParam is from the functionB execution that I didn't develop here. I need to pass to functionA the strParam I get when functionB is executed. (should I edit my post to be more clear ?) - Tari-Green

2 Answers

0
votes

If a parameter is a function then you can call it directly as the parameter name if it's being passed to another function:

functionB(fnParam:Function){
    fnParam('strParam');
}

The issue here looks like like the functionA is null when it's being passed through to functionB. This is possibly because they're in different files / classes but you'll probably want to debug before functionB is called to make sure functionA is accessible.

0
votes

Ok, I made my code working, and I think it could be a static story. FunctionA is not static, and when I pass it as a parameter of the static FunctionB, this works :

private static var functionACallback:Function;

public static functionB( functionA:Function ):void
{
    functionACallback = functionA; //set the static functionACallback
    var strParam = getSomeStringResult(); //get the string
    functionACallback(strParam); //call the static var with parameter
}

I don't entirely understand the issue here, but the above code resolve the problem.

defenestrate.me's answer was helpful.