Forwarding Variable Arguments

I encapsulate a remote access service call in my own RemoteObject class. All this works fine, except when I have to deal with variable parameters passed to a remote call. Since this is a call to NetConnection.call , I should be able to pass variable arguments, but since I encapsulate NetConnection.call , it causes errors. This my method currently looks like this:

 public function call( method : String, callback : Function, ... args ) : void { var responder : Responder; responder = new Responder( callback, onResponderStatus ); this._nc.call( this._remoteObject + "." + method, responder, args ); } 

As you can see, my method takes a variable argument parameter as the last parameter. I am trying to pass these parameters to the NetConnection.call method. But as part of my method, args will be of type Array. How to redirect variable arguments to NetConnection.call correctly?

+4
source share
1 answer

Function::apply is what you are looking for ... after all, it should look like this:

 this._nc.call.apply(this._nc, [this._remoteObject + "." + method, responder].concat(args) ); 

Greetz

back2dos

+7
source

All Articles