4 Replies Latest reply on Oct 13, 2006 2:55 PM by sd12013

    How to Rotate MC to Specific Degrees

    sd12013
      I have an MC with rotation assigned to the up and down keys on the number pad (8/up = 104 and 2/down = 98), This works great but I'd like to limit how far the rotation goes to stop at say 30 degrees when the 8 is pushed and held and stop at -30 when the 2 is pushed and held. I'd also like the MC to return to 0 when neither up or down is being pushed.

      My AS isn't so great but I'm learning a lot through these comments. Any help is greatly appreciated?

      Here's what I have so far:

      onClipEvent (keyDown) {
      if(Key.isDown (104)) {
      this._rotation -= 10;
      }
      if(Key.isDown (98)) {
      this._rotation += 10;
      }
      }
        • 1. Re: How to Rotate MC to Specific Degrees
          S4Potential
          Use a conditional statement

          if (this._rotation >= -30) this._rotation -= 10;

          I leave you the other one as an exercise :o)
          • 2. Re: How to Rotate MC to Specific Degrees
            sd12013 Level 1
            Thanks Potential! That worked beautifully. I was pretty close.

            Any ideas on the other part? - How to make the MC return to the 0 point when neither up nor down is pressed? I'm guessing it has something to do with addListener but I cannot figure out the syntax. I've tried it lots of different ways but I can't seem to get the language correct. My guess is that you have to first establish the resting point at 0 degrees and listen for an onKeyUp. Then when the key is released it triggers the rotation to 0. I'm guessing I'd have to set up two listeners, one for each key. Does that sound right? Can you or anybody out there steer me in the right direction?

            As always my appreciative thanks.

            -r
            • 3. Re: How to Rotate MC to Specific Degrees
              S4Potential Level 1
              If what you want to do is to keep the object rotated as long as a key is holded down and then bring it back to 0 when the key is released the following will do the trick

              onClipEvent (keyUp) {
              this._rotation = 0;
              }

              Simple, isn't it?-)

              Spend some times reading the Actionscript dictionary in the help. Pick a topic and play with its examples for an hour. Modify those examples. Do that few times a week and you'll be amazed how fast you'll get a good grip on things.

              Tip: use traces to help you see when things are executed and when values change.
              • 4. Re: How to Rotate MC to Specific Degrees
                sd12013 Level 1
                Brilliant. Works great. Thanks for your help!