PDA

View Full Version : Override a function with (rest)


relix
03-27-2007, 12:38 PM
I'm making extensive use of LocalConnections, and I would like to override the LocalConnection.send() method in a custom class derived from LocalConnections.

I just need to add a string-id to the connectionName. The problem is "passing through" the (rest) parameters. Since, correct me if I'm wrong, if I do it like this:


override public function send(conName:String, methodName:String, ... args):void
{
super.send(conName + this.id, methodName, args);
}


This would send an array of parameters through, which is wrong. I need something like this:


override public function send(conName:String, methodName:String, ... args):void
{
super.send(conName + this.id, methodName, args[0], args[1], args[2], ...);
}


Anyone has any ideas on how to accomplish this? I hope I explained it well.

newblack
03-27-2007, 03:18 PM
args.unshift( conName + this.id, methodName );
super.send.apply( this, args );

relix
03-28-2007, 11:36 PM
Thanks! Works perfectly.