Is there a way to pass a member function of another class as a function parameter in as3?

For example, I have a function in class A:

    private function functionA(f:Function):void
    {
        var objB:B;
        objB.f();
    }

Is there a way to pass a non-static public member of class B as a parameter to function A? (from inside class A, of course) I know that such a syntax exists in C ++, but I'm not sure if you can do it in flex / as3

+3
source share
1 answer

Of course:

var a : A = new A();
var b : B = new B();

a.functionA(b.functionB);

...

private function functionA(f:Function):void
{
    f();

    // or

    f(1, "hi");
}

A case associated with a function carries over with it. If you need to call a function on another instance callf.apply(instance, [1, "hi"])

AS3 has no idea about delegates or type-as-type signature functions, so you need to know the arguments to pass.

+8
source

All Articles