Karl DeSaulniers wrote:
Using AS2.
When is it best to use the :Void ? and what is the difference between
that and :void ?
You use void when a function doesn't return anything. In fact, there are
some languages, like Pascal and, I believe, Fortran, that have that built
in. In Pascal, a
void is good when you compile - if your method does not return something and
you try to return something from the method, your compiler will complain
which is good:
private function foo():void {
return true;
}
// 1051:Return value must be undefined.
Also, if you define something being
If I remember correctly, in AS2, you need to write a complete function
signature including the scope.
Try including the scope on the functions that stopped working when you added
:Void
*public* function fName():Void {
gotoAndPlay(2);
}
You can choose between internal, private, protected
Besides the compiler checking, specifying the return type is also good when you
write code - enforces you to return the correct type and code correctly. Also
helps apps like FlashDevelop know what the method returns, so great with
code-hinting.
Jason Merrill
Bank of America Global
:Void is AS2, and :void is AS3
The definition of void is nothingness: the state of nonexistence...
The syntax of functionName():void{} simply states that the function returns
nothing... i.e. there is no return at the end of the function.
Although specifying a :void return type is not necessary
Karl, a function returns something if you include a line return
value at the end of the function...
For example, if you had a function that returned a random number below
100:
function giveMeARandomNumberBelow100():Number
{
var myRandomNumberBelow100:Number = Math.random() * 100;
Let's say I wanted to do something like this...
trace(Taka + getLastName(Taka));
function getLastName(firstName:String):String{
if(firstName == Taka){return Kojima;}
else{return ;}
}
That function returns a String. Having a gotoAndPlay() inside a function is
not a return value.
Hope that
7 matches
Mail list logo