views:

314

answers:

1

I'm encapsulating a call to a remoting service in my own RemoteObject class. This all works fine except when I have to deal with variable parameters that are being passed to the remote call. Since this is a call to the NetConnection.call, I should be able to pass variable arguments but since I'm encapsulating the NetConnection.call it's throwing up errors. This is what my method currently looks like:

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 arguments parameter as the last parameter. I'm trying to pass these parameters to the NetConnection.call method. But, within the scope of my method, args would be of type Array. How do I properly forward the variable arguments to NetConnection.call?

+2  A: 

Function::apply is what you are looking for ... in the end, it should look like this:

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