RE: [Flashcoders] To Void or not to void?? That is my question..
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
Re: [Flashcoders] To Void or not to void?? That is my question..
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.bizwrote: 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 -- http://ericd.net Interactive design and development ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] To Void or not to void?? That is my question..
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 or public. Until you understand their purpose more, use public. On Tue, Jul 14, 2009 at 12:57 AM, Karl DeSaulniers k...@designdrumm.comwrote: That is what I figured. Then why would my function not fire the gotoAndPlay when there was a :Void and would when removed?? This isn't a bug is it? I mean were talking about a simple function fName():Void { gotoAndPlay(2); } Not working and a function fName() { gotoAndPlay(2); } Working... This is why I thought I might be missing something about the :Void. Maybe its something else in my code, but I don't think so. Here is the code I am working on: I took Jiri's advice on fixing the function calls on my tweens, but it either is not firing the function or not firing the gotoAndPlay. my first thought was that because the other tweens started working after I made the change to the function call, that this was a :Void culprit. [code] var beginAlpha = 0; var endAlpha = 100; var quoteShowY:Number = 219.9; var quoteHideY:Number = -219.9; this.quoteRequest_mc._x = 354.1; this.quoteRequest_mc._y = quoteHideY; this.quoteRequest_mc._alpha = 0; function formVisible():Void { this.quoteRequest_mc.gotoAndPlay(startQuote); } function formHidden():Void { this.quoteRequest_mc.gotoAndStop(1); } function showForm() { this.quoteRequest_mc.alphaTo(endAlpha,5,easeincirc,.5); this.quoteRequest_mc.ySlideTo(quoteShowY,5,easeincirc,.5,formVisible); } function hideForm() { this.quoteRequest_mc.alphaTo(beginAlpha,5,easeincirc,.5); this.quoteRequest_mc.ySlideTo(quoteHideY,5,easeincirc,.5,formHidden); } Thanks for taking the time to answer my question everyone. Karl On Jul 13, 2009, at 11:43 PM, Taka Kojima wrote: 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 helps. -Taka On Mon, Jul 13, 2009 at 9:29 PM, Karl DeSaulniers k...@designdrumm.com wrote: Thanks for the quick response Taka, So what contitutes a return? I have used the :Void on functions that had a gotoAndPlay() inside it and it didnt work. But if I removed the :Void, it did!?! Karl On Jul 13, 2009, at 11:18 PM, Taka Kojima wrote: :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 in AS3, it is considered best practice to include it. I believe it will generate warnings if you don't. In AS2, it really doesn't matter if you do :Void after functions. The reason this syntax exists is to make it easy for compilers to easily identify problems in regards to object types, i.e. if you're trying to use the return value of a function as a MovieClip when it should really be an Array, or void. It also makes it easier for you to see what type of value the function is returning just by looking at the top of the function definition. - Taka On Mon, Jul 13, 2009 at 9:07 PM, Karl DeSaulniers k...@designdrumm.com wrote: Using AS2. When is it best to use the :Void ? and what is the difference between that and :void ? I have a somewhat understanding of what each are, I am asking more to you (The List) as a programers, what is the best case scenarios to use these things? What are the advantages and why use them if say, your function works without them? 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(); ??? Thanks for any clarification anyone can give me. Best, Karl DeSaulniers Design Drumm http://designdrumm.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Karl DeSaulniers Design Drumm http://designdrumm.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders
RE: [Flashcoders] To Void or not to void?? That is my question..
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 Learning Shared Services Solutions Development Monthly meetings on the Adobe Flash platform for rich media experiences - join the Bank of America Flash Platform Community ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] To Void or not to void?? That is my question..
: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 in AS3, it is considered best practice to include it. I believe it will generate warnings if you don't. In AS2, it really doesn't matter if you do :Void after functions. The reason this syntax exists is to make it easy for compilers to easily identify problems in regards to object types, i.e. if you're trying to use the return value of a function as a MovieClip when it should really be an Array, or void. It also makes it easier for you to see what type of value the function is returning just by looking at the top of the function definition. - Taka On Mon, Jul 13, 2009 at 9:07 PM, Karl DeSaulniers k...@designdrumm.comwrote: Using AS2. When is it best to use the :Void ? and what is the difference between that and :void ? I have a somewhat understanding of what each are, I am asking more to you (The List) as a programers, what is the best case scenarios to use these things? What are the advantages and why use them if say, your function works without them? 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(); ??? Thanks for any clarification anyone can give me. Best, Karl DeSaulniers Design Drumm http://designdrumm.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] To Void or not to void?? That is my question..
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; return myRandomNumberBelow100; } Pointless function of course, but you get the idea? Barry. -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Karl DeSaulniers Sent: Tuesday, 14 July 2009 4:30 p.m. To: Flash Coders List Subject: Re: [Flashcoders] To Void or not to void?? That is my question.. Thanks for the quick response Taka, So what contitutes a return? I have used the :Void on functions that had a gotoAndPlay() inside it and it didnt work. But if I removed the :Void, it did!?! Karl On Jul 13, 2009, at 11:18 PM, Taka Kojima wrote: :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 in AS3, it is considered best practice to include it. I believe it will generate warnings if you don't. In AS2, it really doesn't matter if you do :Void after functions. The reason this syntax exists is to make it easy for compilers to easily identify problems in regards to object types, i.e. if you're trying to use the return value of a function as a MovieClip when it should really be an Array, or void. It also makes it easier for you to see what type of value the function is returning just by looking at the top of the function definition. - Taka On Mon, Jul 13, 2009 at 9:07 PM, Karl DeSaulniers k...@designdrumm.comwrote: Using AS2. When is it best to use the :Void ? and what is the difference between that and :void ? I have a somewhat understanding of what each are, I am asking more to you (The List) as a programers, what is the best case scenarios to use these things? What are the advantages and why use them if say, your function works without them? 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(); ??? Thanks for any clarification anyone can give me. Best, Karl DeSaulniers Design Drumm http://designdrumm.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Karl DeSaulniers Design Drumm http://designdrumm.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] To Void or not to void?? That is my question..
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 helps. -Taka On Mon, Jul 13, 2009 at 9:29 PM, Karl DeSaulniers k...@designdrumm.comwrote: Thanks for the quick response Taka, So what contitutes a return? I have used the :Void on functions that had a gotoAndPlay() inside it and it didnt work. But if I removed the :Void, it did!?! Karl On Jul 13, 2009, at 11:18 PM, Taka Kojima wrote: :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 in AS3, it is considered best practice to include it. I believe it will generate warnings if you don't. In AS2, it really doesn't matter if you do :Void after functions. The reason this syntax exists is to make it easy for compilers to easily identify problems in regards to object types, i.e. if you're trying to use the return value of a function as a MovieClip when it should really be an Array, or void. It also makes it easier for you to see what type of value the function is returning just by looking at the top of the function definition. - Taka On Mon, Jul 13, 2009 at 9:07 PM, Karl DeSaulniers k...@designdrumm.com wrote: Using AS2. When is it best to use the :Void ? and what is the difference between that and :void ? I have a somewhat understanding of what each are, I am asking more to you (The List) as a programers, what is the best case scenarios to use these things? What are the advantages and why use them if say, your function works without them? 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(); ??? Thanks for any clarification anyone can give me. Best, Karl DeSaulniers Design Drumm http://designdrumm.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Karl DeSaulniers Design Drumm http://designdrumm.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders