4 Replies Latest reply on Aug 19, 2008 5:58 AM by kabunia

    How do I speed up (easeIn) rotation?

      I have a movieclip, mc_fan and on click of btn_Start, I want to gradually increase the rotation of mc_fan until it is rotating by 5 degrees each frame and continues to rotate until I press another button. Here's my code that doesn't quite work the way I want it to. Thanks for your help!

        • 1. Re: How do I speed up (easeIn) rotation?
          ZodiacHSX
          Maybe you could say what doesn't work :)

          Usual disclaimer: I know absolutely nothing about Flash, just trying to apply stuff from other languages

          Dont't you want to increase speed, not varSpeed? and doesn't the check for speed >=5 need to happen on every frameupdate as well? And don't you want the rotation to still add up even after 5 has been reached? What happens if the animation runs so long that the number is out of range? No idea if angles are given in radians or degrees... if it's radians, substitute 360 with 2*pi

          mc_fan.onEnterFrame = function():Void{
          if(speed <= 4.5)
          speed += 0.5;

          mc_fan._rotation = (mc_fan._rotation+speed)%360;
          }
          • 2. Re: How do I speed up (easeIn) rotation?
            Level 7
            var speed:Number = 0;

            function fanOn()
            {
            speed = 0;
            mc_fan.onEnterFrame = function():Void
            {
            speed += .5;
            speed = Math.min(5, speed);
            mc_fan._rotation += speed;
            };
            }
            function fanOff()
            {
            delete mc_fan.onEnterFrame;
            }
            fanStart.onRelease = function()
            {
            fanOn();
            }
            fanStop.onRelease = function()
            {
            fanOff();
            }


            Slight mods... if you have two buttons fanStart and fanStop, this should do
            what you need.

            --
            Dave -
            www.offroadfire.com
            Head Developer
            http://www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/


            • 3. Re: How do I speed up (easeIn) rotation?
              Level 1
              Thanks for responding ZodiacHSX. I had a typo in my code in my original thread, but that's not where I'm having the problem anyway. To your point about rotation adding up even after it reaches 5...once speed >= 5, I want the first onEnterFrame function (before the "if" statement) to be deleted so that speed does not add up once it reaches 5. I also now see that I need an onEnterFrame inside the "if" statement so that once I delete the first onEnterFrame, mc_fan will continue to rotate at 5 degrees with the 2nd onEnterFrame function. I'll see if that works.
              • 4. How do I speed up (easeIn) rotation?
                Level 1
                Dave, thanks for your response and code. I was a little confused by the Math.min statement, but I've looked it up in Flash and it now makes a lot of sense.

                Thanks again.