Arguments, a piece of history?
By Gerben Robijn on Dec 15, 2006 in Actionscript 2, Actionscript 3, Flex
Did you use the arguments object in actionscript 2? This vague object that you could call without having seen it anywere. Well it has gotten a lot better with Actionscript 3. They introduced the rest keyword.
This is how it works:
Actionscript:
-
//Create a function with the rest keyword like : "... args"
-
public function average (name:String, ... args):void{
-
var total:Number = 0;
-
-
//Handle the rest keyword like an array
-
for(var i:Number=0; i<args.length; i++){
-
total += args[i];
-
}
-
-
var avarage:Number = total / args.length;
-
-
trace("The average of " +name +" is: " +average);
-
// traces: The average of Averagetest is: 2.75
-
-
}
-
-
// Just call the function with a name and a variable number of numbers
-
average("Averagetest", 2,2,3,4);
I even tried the arguments Object in actionscript 3 but it was kinda buggy. So I just dropped that, the rest keyword works fine and you don't have to guess where it is coming from. Bye bye arguments.






