3 Replies Latest reply on Aug 22, 2009 8:44 AM by Rothrock

    Make a Tween always play in reverse?

    Rothrock Level 5

      I'm using the native Tween class and have a several tweens which make a button, when clicked, fly up into the corner of the screen. Then some time later yoyo() that tween to bring the button back to where it started.

       

      The problem is that we have a replay button that replays from certain points on the timeline.

       

      I want that if on the "screen" (not flash screens just our term for the range of frames that correspond to the timeline between those certain replay points) the user clicks replay that the button will always play the tween backward, i.e., flyout from the upper corner back to the "start" point.

       

      Since there is no reverse() method or playInReverse() the only choice seems to be yoyo(). And one would think that fforward() followed by a yoyo() would make it always play backward. But I can't make it seem to work.

       

      So my question is, "Is there a way to ensure that a tween, regardless of how it last player or is still playing, can be made to go to the end and then play backwards?"

       

      Thanks.

        • 1. Re: Make a Tween always play in reverse?
          Rothrock Level 5

          Okay I think I've figured something out.

           

          About yoyo() the help file says, "..instructs the tweened animation to play in reverse from its last direction of tweened property increments..."

           

          What it doesn't make explicit is that yoyo actually changes the tween around so that the beginning becomes the end and the end becomes the beginning. So to make it play backward again all I need is a start();

           

          So yoyo actually doesn't make it play backwards. It turns the tween around and then plays it frontwards!

           

          I think I might be okay now that I understand that. But if anybody has any wisdom I could certainly use it. Thanks.

          • 2. Re: Make a Tween always play in reverse?
            NSurveyor Level 2

            I think you're right, Rothrock. What bothers me the most about using yoyo(); is that if you call it before the tween has ended, the new beginning position is the current position. That is the tween has effectively truncated off the ending bit, which it had not yet reached. And also, because it is just switching the beginning and end positions, the easing used is also backwards. If it originally eased in, then in reverse, it should be an ease out, but this is not the case.

             

            If you are using a frame-based tween instead of by seconds, you might be able to make use of the prevFrame() method:

            myTween.stop();
            onEnterFrame = function(){
                 myTween.prevFrame();
                 if(myTween.position == 0){
                      trace("Reverse complete!");
                      delete onEnterFrame;
                 }
            }
            

             

            Of course you could also use a setInterval if you don't want to involve using a MovieClip's onEnterFrame event handler. But anyway, I think this method is nice because you are essentially scrubbing the Tween like a timeline, preserving all of its properties, including the easing.

            1 person found this helpful
            • 3. Re: Make a Tween always play in reverse?
              Rothrock Level 5

              Thanks. I hadn't even thought about the easing issue. I think the real answer is not to use the built in Tweens!

               

              Actually I think that I figured this all out before. And it is all just such a mess that my brain refuses to believe it and that is why I had to do it again.

               

              BTW, haven't seen you around for awhile. How is it going? Are you out of high school yet? What are you doing in the world?