« Learning MVC in Flex - Cairngorm
» CAPTCHA in Flex - Running Example

ActionScript, Flex 2

Rest parameter

Virgil Cristea | 31.10.07 | Comment?

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:
  • Technorati
  • StumbleUpon
  • del.icio.us
  • NewsVine
  • Reddit
  • Digg
  • Furl
  • co.mments
  • blogmarks
  • Slashdot
  • description
  • Taggly
  • YahooMyWeb
  • connotea
  • Webride




Tags: , ,

This post was written by Virgil Cristea

Views: 723

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="">

:

:


« Learning MVC in Flex - Cairngorm
» CAPTCHA in Flex - Running Example