7 Replies Latest reply on Mar 24, 2007 3:31 PM by Greg Dove

    rotation goes negative

    Starlover_jacob Level 1

      a question about my problem; Is this normal? And how do i solve this problem?

      this is my code:

      function rpmrotate()
      if(instance_six.hitTest(_root._xmouse, _root._ymouse, false))
      instance_pin._rotation +=5;
      output of my trace:

      I would liked it to go up.. and up.. and up.. not negative?!? :-(

      Please some help.
        • 1. Re: rotation goes negative
          kglad Adobe Community Professional & MVP
          you can add 360 to any negative rotation to convert to a postive number with the same effect.
          • 2. Re: rotation goes negative
            Starlover_jacob Level 1
            Thanx.. the numers are tuning positive again..
            But how do i solve my if statement now?

            if(instance_pin._rotation+360<=201) Does not work... My trace gives a constant -2.

            • 3. rotation goes negative
              SymTsb Level 2
              Flash's rotation works from -180 to 180, not 0 to 360. Huge misconception that most people have. This does cover 360 degrees but not in the most standard of ways.

              0-180 corresponds to 0-180 as you'd expect then it becomes -180-0 corresponds to 180-360.

              Up to 180, you'll be able to use the method you were using. Increment your _rotation += 5 as you were but add a new variable to the mix counter_control. This counter will start at the same number as the _rotation (let's say 25). Each time you rotate the whatever 5, increment the counter_control 5 as well. With a counter control, you can test that rather than the actual rotation value which can never hit a positive number above 180. This will allow you handle 180-360 better.
              • 4. Re: rotation goes negative
                Starlover_jacob Level 1
                Here is my fla file.

                I will try your option, thanx for writing.

                I hope there is a nicer way to animate this..
                any input is welcome.

                Thanx a lot!
                Greetz, jacob
                • 5. Re: rotation goes negative
                  Starlover_jacob Level 1
                  a new link
                  the rotationcounter works fine.
                  thanx a lot!.
                  http://members.lycos.nl/jacobhingst/troep/rpm clock2.fla

                  i have an example of speed in it.. but i don't understand.. maybe there's someone who can ad this functionality for me? so it gives it a real rpm look..

                  i also have the problem that if i upgrade the +=5 to a +=10.. the pointer is missing the target area..
                  any sugestions how to improve the speed and also make it work correctly?

                  (sory for my english.. i'm from holland)

                  Greetz, jacob
                  • 6. rotation goes negative
                    Greg Dove Level 4
                    I was reading this out of interest. I've had similar difficulties with tracking using the _rotation property in the past.

                    SymTsb's revelation (I'd observed this but had forgotten it) prompted me to write this funciton. Its simple but I'll probably use something like it in the future for more intuitive (at least the way I think) checks on the _rotation property. I think its correct.
                    • 7. Re: rotation goes negative
                      Greg Dove Level 4
                      I downloaded your fla and took a look at it.

                      Have you considered using a tween class to do your tweening for you? There a few different classes floating around to do that sort of thing. Its kind of like an actionscript version of what you can do in the timeline in the flash authoring environment, but because its in actionscript you have runtime control over all the tweening options.

                      I got your fla working with an older version of something called the zigo tween engine (all that's required is to include an external lmc_tween.as file to be able to use it) and by doing so was able to avoid the need for a lot of the code that you have...mainly because it handles all the tweening so I didn't need all that part. Let me know if you want me to post the code. You would need to find and download the lmc_tween.as file to include for the tweening support or I could send you the original zip if I can find it. The benefit with this type of approach is that you can set both speed (duration) of the tween and the easing type... which could be helpful with the rpm meter simulation.

                      If you want to continue on the same track as you started (and that's fine too... and probably the best way to learn) then you might also find this line of code helpful... it provides an additional _rotation360 property on all movieclips that lets you access the rotation value in the same way as the function I posted above (avoiding the need to count) ... you can use it to set the rotation as well but in that way its really not a lot different from using the regular _rotation property.