Friends methods / classes for unpacked AS3 classes

Hey. I am wondering if I can have an AS3 batch () class for a private method for the main class in a file. For example:

package demo
{
    public class MyDemoClass
    {
        var helper:FriendlyHelperClass = new FriendlyHelperClass(this)
    }

    private function methodToCall():void
    {
        ...
    }
}

public class FriendlyHelperClass
{
    public function FriendlyHelperClass(demo:MyDemoClass)
    {
        demo.methodToCall()
    }
}

      

Calling the ToCall () method from the FriendlyHelperClass will fail because it is a private member of MyDemoClass. Is there a way to call methodToCall () from the FriendlyHelperClass without extending MyDemoClass.

Basically I'm looking for inner class functionality that Java or some kind of C ++ style friends class has.

+2


source to share


3 answers


The short answer is no.



You can never access a private member outside of a class in ActionScript. What you can do is use a namespace instead of a private scope. This will give some members access to the selected classes. This is the closest friend class you will get in AS3.

+2


source


I'm afraid this is not possible, but if you make the class dynamic, then you can edit it while the program is running and perhaps add useful functions to it to access private functions. However, I haven't tried it.



Dynamic classes

0


source


Without testing your code and knowing what your total problem is. you can try passing the required functions to the built-in class as a callback. eg.

helper.methodToCallCallback = this.methodToCall;

      

then inside the FriendlyHelperClass:

this.methodToCallCallback();

      

0


source







All Articles