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 returned as an expected part of the
method but do not return something you'll also get an error

private function foo():Boolean {

// 1170: Function does not return a value.

On Tue, Jul 14, 2009 at 2:58 AM, Kerry Thompson <al...@cyberiantiger.biz>wrote:

> 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 function returns something, while a procedure doesn't. A
> Pascal programmer would use a function to do something like perform a
> calculation--let's say, figure the square root of a number. A procedure
> would do something like drawing a line.
> Void is AS2, and void is AS3. I have no idea why the spelling change, but
> ActionScript is, of course, case sensitive.
> > What are the advantages and why use them if say, your function works
> > without them?
> Clarity, mainly. Also, in AS3, if you have strict type checking on (it's
> the
> default), every function must have a type, so you use void when your
> function won't return anything. If you declare a function as :void, and
> have
> a return in it, I believe the compiler throws an error.
> > I know that the Void is a Boolean, but I also know you cant use it
> > when the statement returns something.
> > Does this "return" include any of the basics like gotoAndPlay? or
> > does it literally mean a return();
> Void actually isn't a Boolean. Technically, its value is undefined. AFAIK,
> :void can only be used as the return type of a function. You can't declare
> a
> variable as void.
> Down on the nuts and bolts level, every function is a subroutine. You call
> it, and it returns control to the calling object. So every function
> returns;
> some pass a value back, and some don't.
> HTH.
> Cordially,
> Kerry Thompson
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Interactive design and development
Flashcoders mailing list

Reply via email to