AS3 Responder and FMS
I'm trying to communicate with Flash Media Server through the Responder
class because I don't want to put public methods in my class that receives the callbacks from the server.
Everyhing goes just as planned when the client is the one calling the methods but once the server needs to call a method on the client, I'm forced to define a public method.
I'm currently doing something along the lines of:
nc.client = {
someCallback: somePrivateFunction
};
N开发者_如何学Goow someCallback
can get invoked by the server and the method somePrivateFunction
in my class can still be private, this is exactly what I want.
I was wondering if there is a cleaner solution?
Your code is pretty clean I believe. I'm not so sure you could make it any easier if you want a private function with a public handler;
The only drawback I can see of this method is the inability to override someCallback, but I haven't really run into any real world issues with this. I think in larger projects it makes more sense to build an entire new class around controlling client/server calls, i.e.
nc.client = new ConnectionClient(nc, myself);
Another method may be to handle all function invocations yourself, i.e. making all the server calls call one public method, and then yourself determining what happens based on those calls.
You could also have your client dispatch events rather than mapping directly to methods. This would add a layer between the server calls and your class, but it might be "cleaner" for larger projects.
Clean is very subjective :)
精彩评论