How do I accept multiple arguments in a custom method? Like:
Proxy(101, 2.02, "303");
function Proxy(args:Arguments){
Task(args);
}
function Task(var1:int, var2:Number, var3:String){
// work with vars
}
You wouldn't be able to just pass the args array through like you have in your question. You'd have to pass each element of the args array seperately.
function Proxy(... args)
{
// Simple with no error checking.
Task(args[0], args[1], args[2]);
}
Udate
After reading one of the comments, it looks like you can get away with:
function Proxy(... args)
{
// Simple with no error checking.
Task.apply(null, args);
// Call could also be Task.apply(this, args);
}
Just be careful. Performance of apply() is significantly slower than calling the function with the traditional method.
You can also use apply(thisArg:*, argArray:*):*
method from the Function
object.
example:
package{
public class Test{
public function Test(){
var a:Array=[1,"a"];
callMe.apply(this,a);
}
public function callMe(a:Number,b:String):void{
trace(a,b);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With