0

What is the use of void in Action Script 3.0?

Can any one give brief explanation with example?

Benny
  • 2,250
  • 4
  • 26
  • 39
  • duplicate : http://stackoverflow.com/questions/4280132/what-is-the-point-of-void-in-as3/4280167#4280167 – Patrick Apr 08 '11 at 07:36

3 Answers3

3

void is an actionscript keyword, used to define no return type in function signature, and force compiler to ristrict/check it

eg

public function func():void
{
  //do some thing
}

above function retuns nothing

Hopefully this will helps

Imran
  • 2,906
  • 1
  • 19
  • 20
2

It's a function type. It means that it doesn't return any data By default Flash always expect to return a value. If you write a function like this for example: ActionScript Code:

function myFunction(){

}

Flash assumes that returning a value is still possible and so watch for it which uses ressources. When you specify :void you are actually telling Flash to not expect any return value so Flash does not waste resources watching for it.

Nirmal- thInk beYond
  • 11,847
  • 8
  • 35
  • 46
0

Easiest way for me to remember it is that it is a function that carries out an action (in other words does something) rather than returns something.

Example:

function myFunction(event:MouseEvent): void   
{ this.play; //or some other action}
//the above function returns nothing


function mySum(a:int, b:int): int
{var myresult:int = a+b;
return myresult;}
//the above function would return the sum of two integers that you passed into it
JRulle
  • 7,448
  • 6
  • 39
  • 61
  • what? "myFuntion" will return the "play" comment... Please.. take me deeper.. I didn't yet get.. – Benny Apr 11 '11 at 10:48