3

I noticed that i can set a return type on a function to 'Void' aswell as 'void' and just wondered if there was and benefit of either?

AsTheWormTurns
  • 1,318
  • 3
  • 13
  • 26
rorypicko
  • 4,194
  • 3
  • 26
  • 43

3 Answers3

10

Void (with uppercase "v") was ActionScript 2 version of ActionScript 3 void.

AS3 docs (void):

Specifies that a function cannot return any value. The void type is a special type that contains exactly one value: undefined. It is special in that its use is limited to the return type of a function. You cannot use void as a type annotation for a property.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/specialTypes.html#void

AS2 docs (Void):

The Void data type has one value, void, and is used in a function definition to indicate that the function does not return a value, as shown in the following example:

//Creates a function with a return type Void
function displayFromURL(url:String):Void {}

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000037.html

AsTheWormTurns
  • 1,318
  • 3
  • 13
  • 26
  • cheers,i just wondered why FlashDevelop let me put it with a capital! – rorypicko Feb 03 '12 at 14:01
  • @RoryPickering: you should have mention FlashDevelop and insert the related tag. ;-) Anyway, there could be a couple of reasons (or more): the first is to help you with legacy code. The second is that FlashDevelop can be used with HaXe too, and HaXe features a Void type. – AsTheWormTurns Feb 03 '12 at 14:32
2

No there isn't. void type just says the compiler that no value will be returned.

ThomasM
  • 2,647
  • 3
  • 25
  • 30
2

void type indicates to the compiler that the function you have written will not return any value, in the other side if you indicate other type int than void the compiler expect that you return int.

Ex:

function foo(a:int):int 
{ 
   // here the compiler expect that somewhere
   // in your function you return an int
   return a;
}

AS2 = :Void
AS3 = :void

Swati Singh
  • 1,863
  • 3
  • 19
  • 40