2 Replies Latest reply on Sep 12, 2007 10:40 AM by Mister Peanut

    My code for Throwing Objects

    Mister Peanut

      I am working on learning actionscript, and would appreciate it if anyone could help me understand a section of code:

      function onEnterFrame(Void):Void

      I am confused as to when where and why I need to use Void.

      Additionally, I would like to find a way to toss the object in a way that it will spin depending on where it is picked up. For example, if it is picked up by a corner, it will spin more than if it is picked up by the center and thrown. I know I have seen this done before, but I can't remember where.



        • 1. Re: My code for Throwing Objects
          Some1Won Level 1
          I don’t think you need the first void in the brackets. The parameters a method takes in there would go inside the brackets. If a method took in a number, it would go: function aFunctionName(inputNumber:Number):Void

          Since onEnterFrame takes in no parameters, I’m guessing that’s why void is there. But it can also be written: function onEnterFrame():Void

          The second void specifics what the method would return after it’s called. If it returned a number, it would be: function aFunctionName():Number. Since onEnterFrame method returns ‘nothing’, that is why the void is there.

          However, from your attached code, (which doesn’t appear strict AS2), you can also leave this off and have: function onEnterFrame()

          Conversely, you could have written you init() method like: function init(void):Void

          As for spinning, I’m assuming this means actually rotating the ball. You could try something like when the user clicks on the ball, you get the difference between the position of the mouse and the ball’s center, and then use that as a rotation speed/magnitude and spin it by that amount every frame.
          • 2. Re: My code for Throwing Objects
            Mister Peanut Level 1
            Thanks Some1Won,

            I got this code originally from a Friends of ED Actionscript Animation book I am working through, and there is little explanation of Void - that I understand, anyway. Just to clarify, I'm actually using a playing card - not a ball, for my throwing action (I just used code that was already there, and am working on modifying it for my needs).

            Thanks for the spinning advice! I'll work on that and see what I can come up with!