4 Replies Latest reply on Jul 20, 2006 10:42 PM by OniLink

    Actionscript Easing

    OniLink Level 1
      Hi,

      I'm struggling to find an properly working metyhod for this. As a simple example, I've tried things like:

      spd = 100;
      onClipEvent (enterFrame) {
      spd*=.9;
      if (ty<tpos) {
      _root.thumbHolder._y += spd;
      } else if (ty>tpos) {
      _root.thumbHolder._y -= spd;
      }
      }

      But, because 'tpos' isn't always the same, sometimes the it eases too much and doesn't reach the tpos, OR it gets stuck between less than or greater than.

      Does anyone know of a method that would work in this situation?

      Thanks for any help,
      ~Oni.
        • 1. Re: Actionscript Easing
          Level 7
          OniLink,

          > I'm struggling to find an properly working metyhod for this.

          By "this," and your subject line, I presume you mean easing? If so,
          have you looked at the Tween class?

          Here's a tutorial:
          http://www.kirupa.com/developer/actionscript/tween.htm

          Worth a shot ... it's built-in, and the supplied easing algorithms give
          you quite a few choices.


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Actionscript Easing
            Level 7
            OniLink wrote:
            >
            > Does anyone know of a method that would work in this situation?

            Dynamic ease out is typically achieved with a formula like below (assuming
            your target position is ty)
            ==========
            easeFactor = 2;
            onClipEvent (enterFrame) {
            thumbHolder._y += (ty - thumbHolder._y) / easeFactor;
            }
            ==========

            You will always reach your destination provided the ease factor is greater
            than 0.5. and note that values between 0.5 and 1 give you some rapid
            elastic effect which generally don't look very good.

            And you will also need to set up a system to detect that if you are close
            enough to your destination, then you must cancel the enterFrame process.
            Look into the onEnterFrame event handler to do this rather than
            onClipEvent(enterFrame).

            Alternatively, use the Tween class and experiment with the various easing
            styles provided. You can also create your own easing styles with the tool
            below:
            http://timotheegroleau.com/Flash/experiments/easing_function_generator.htm

            hth,
            Tim.
            • 3. Re: Actionscript Easing
              micahkoga
              There's two ways to do this:
              1. Use the tween class. It has automatic easing:
              import mx.transitions.Tween;
              var myTween:Tween = new Tween(myMovieClip_mc, "_x", mx.transitions.easing.Elastic.easeOut, 0, 300, 3, true);
              see help for more info

              2. Do it the old fashioned way:
              I usually make an increment variable
              var incr:Number = (goal - current)/number;
              object.property += incr;

              you don't need the condition. the '+=' will take care of the direction
              • 4. Re: Actionscript Easing
                OniLink Level 1
                Thank you all for your help. I like doing it the old fashion way, so that's what I went with in the end. Works perfectly!

                Thanks again,
                ~Oni.