Using the (… args) Operator.

The usage is so simple and clear. Using this operator we can pass n number of variables values and hold them for calculation.The variable can be of any type and the final args contains the array of elements we pass.the below example will make you clear.

Flex Code Example:

CreationComplete=”init()” –>Call this on Application creation.

scrpt Code

private function init():void
{
lbl.text=String(average(100,100,100,100,100));
}
private function average(… args):Number
{
var sum:Number=0;
var i:int;
for(i=0;i<args.length;i++)
{
sum+=args[i];
}
return sum/args.length;
}

MXML code

<mx:Label id=”lbl” />

Enjoy the Post and Operator. Make your code simple. 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: