Ooh! Ooh! I just wrote this a few days before you asked. Here's my
solution:
public function call( rpcName: String, responder: Responder,
rpcArgs: Array ): void {
// NetConnection.call() takes a variable number of arguments after the
// RPC call name and the responder. To make a pass-through call from
// one such function (this function) to another
(NetConnection.call()),
// we must make an array of ALL arguments to the target function and
// then call apply() on the Function object we wish to call
(_nc.call).
var callArgs: Array = [rpcName, responder].concat( rpcArgs );
// Function.apply() also wants a "this" reference, so we pass _nc in
too.
_nc.call.apply( _nc, callArgs );
}
As Meinte says, it isn't worth the mess, so I don't use "..." in my own
code. The contents of the function would look exactly the same if you
changed the call signature to match NetConnection's:
public function call( rpcName: String, responder: Responder, ... rpcArgs
): void
And then it's a proper pass-through.
With Latcho's example:
testargs( "a","b",{z:'zz'},[1,2,3],"c" )
private function testargs(... argsA):void
{
trace("#args_A:", argsA.length) ///
traces: #args_A: 5
passingArgs.apply(this, argsA)
}
public function passingArgs(... argsB):void
{
trace("#args_B:",argsB.length) ///
traces: #args_B: 5
for(var i:int=0;i<argsB.length;i++) { trace(argsB[i]); }
};
If passingArgs() isn't a member function of some class, I'm not sure what
you pass as apply()'s first argument, possibly null?
Dave
On 11/28/08, Meinte van't Kruis <[EMAIL PROTECTED]> wrote:
>
> I think I tried something with casting to array or using Function.apply,
> I'm
> pretty sureFunction.apply or call does the trick
>
> after messing around with it I decided it wasnt worth the mess and used
> array's instead..
>
>
> On Fri, Nov 28, 2008 at 4:18 PM, Latcho <[EMAIL PROTECTED]> wrote:
>
> >
> > Hi List,
> >
> > How can I pass a variable amount off function arguments to a next
> function
> > ?
> > Below the way I tried and which fails. While passing them they get
> combined
> > I'd like to remain 5 variables for args_B and not a single string.
> > Stijn
> >
> > CODE:
> >
> > testargs( "a","b",{z:'zz'},[1,2,3],"c" )
> >
> > private function testargs(... argsA):void
> > {
> > trace("#args_A:",
> argsA.length) ///
> > traces: #args_A: 5
> > passingArgs(argsA)
> > }
> >
> > public function passingArgs(... argsB):void
> > {
> > trace("#args_B:",argsB.length) ///
> > traces: #args_B: 1 for(var i:int=0;i<argsB.length;i++) {
> > trace(argsB[i]); } // which traces a string: a,b,[object Object],1,2,3,c
> > };
> >
> >
> > Latcho
> >
> >
> >
> >
> > _______________________________________________
> > Flashcoders mailing list
> > [email protected]
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
>
>
>
>
> --
> M.A. van't Kruis
> http://www.malatze.nl/
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders