Thursday, July 19, 2007

varargs in AS3

ref:
http://weblog.mrinalwadhwa.com/2007/07/19/flex-tip-of-the-day-varargs-in-as3/

// Here’s a bare bone example:

private function
average(... args):Number{

var
sum:Number = 0;
for
(var i:int = 0; i<args.length;i++){

sum += args[i];
}

return
sum/args.length;
}


// Now all the below calls would work

var
a:Number = average(100,200);

a = average(100,200,300);
a = average(100,200,300,400);

a = average(100,200,300,400,500);

No comments: