What is the use of void in AS3

£可爱£侵袭症+ 提交于 2019-12-08 09:06:37

问题


What is the use of void in Action Script 3.0?

Can any one give brief explanation with example?


回答1:


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.




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/5591580/what-is-the-use-of-void-in-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!