package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
// trace(sum()); // throws a runtime error.
trace(sum(1,2,3,4,5)); // Displays: 15
}
function sum(base:Number, ... numbers):Number {
var result:Number = base;
for each (var num:Number in numbers) {
result += num;
}
return result;
}
}
}
|