We love choice

Fx{r} is trying to start the Fx{r} Community! Please join our group on Adobe Groups following this link: http://fxr.groups.adobe.com.
Fx{r} is now on Twitter too. Follow us @ twitter.com/fx_r!
«
»

ActionScript, Flex 2

Rest parameter

Virgil Cristea | 31.10.07 | Comment?

Google Buzz

A very handy parameter is the rest one. Imagine you want a function that will calculate the sum of any number of parameters of type number. One way to do it is to send an array to the function. But one better way is to use the “rest” parameter.

Here is the function:

public function MakeSum(a:int, ... rest):int
{
 var sum:Number = 0;
 for (var i:uint = 0; i < args.length; i++)
 {
        	sum += args[i];
    }
 return a+sum;
}
 
....
MakeSum(1,2,3); //returns 6
MakeSum(15,20); // returns 35

That is all :)

For more info look here.

Share and Enjoy:
  • Twitter
  • Google Buzz
  • LinkedIn
  • Google Bookmarks
  • del.icio.us
  • Digg
  • Sphinn
  • blogmarks
  • Reddit
  • StumbleUpon
  • Facebook
  • DZone
  • FriendFeed
  • Yahoo! Buzz
  • Yahoo! Bookmarks
  • Slashdot
  • MySpace
  • Add to favorites




Tags: , ,

This post was written by Virgil Cristea

Views: 4403

related

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

:

:


«
»