4 Replies Latest reply on Jul 6, 2009 6:51 AM by kglad

    Smoother Tween alternative to ENTER_FRAME function???

    keithwoods Level 1

      I've got a tween which is called using an ENTER_FRAME event listener, as I need the movieclip to constantly tween until it's selected. However, the tween isn't very smooth, it's very jumpy and I'm guessing this has got something to do with the ENTER_FRAME event being constantly called.

      Is there a better way of creating a smoother tween?

      Here's my code...

      ActionScript Code:
      this.addEventListener(Event.ENTER_FRAME, ballFloat);

      private function ballFloat(event:Event):void
              {
                      var myTweenX:Tween = new Tween(this, "x", Regular.easeOut, this.x, randomXBoundary, 10, true);       
                      TweenX = myTweenX;
              }// end of ballFloat function
        • 1. Re: Smoother Tween alternative to ENTER_FRAME function???
          Ned Murphy Adobe Community Professional & MVP

          In what way do you want it to continuously move/tween (aside from the x-direction)?  Did you want it to move with easing such that it seems to have spurts of movement or did you want a constant speed?  Using a Tween approach with easing  and listeners is likely to give you repeated spurts of motion, whereas an enterframe approach could provide a constant incrementing, with dampening if desired based on relative position to something.

          • 2. Re: Smoother Tween alternative to ENTER_FRAME function???
            kglad Adobe Community Professional & MVP

            your problem is caused by using a tween with an enterframe loop.  use one or the other but not both to animate an object.

             

            because you already know how to tween using the tween class, remove your enterframe loop and add a motionfinish event listener to restart your tween.  when the object is selected apply a stop() to your tween:

             

            var myTweenX:Tween 

            function tweenF(e:TweenEvent){
            myTweenX = new Tween(this, "x", Regular.easeOut, this.x, randomXBoundary, 10, true)
            randomXBoundary=Math.random()*whatever;
            }    
            myTweenX.addEventListener(TweenEvent.MOTION_FINISH,tweenF);
            tweenF(new TweenEvent("xxx"));
            • 3. Re: Smoother Tween alternative to ENTER_FRAME function???
              keithwoods Level 1

              Thanks for your help guys.

               

              For the moment I've gone with a tween class as I understand them better.

               

              So what I've got is a tween called myTweenX which is initiated at the start. An event listener is then added to the tween variable, which detects when the tween has finished and starts a function called tweenX.

               

               

              ActionScript Code:
              import fl.transitions.Tween;
                  import fl.transitions.easing.*;
                  import fl.transitions.TweenEvent;

              myTweenX = new Tween(this, "x", Regular.easeOut, this.x, randomXBoundary, 10, true);
                          myTweenX.addEventListener(TweenEvent.MOTION_FINISH,tweenX);


              Now it works to the point where the initial tween above is started, then once finished it calls the tweenX function (see below), and starts a new tween. However, after the tweenX function is called for the first time it stops. I was expecting the MOTION_FINISH event listener to be called again as the tweenX function finishes, but it's not getting called again, and thus the tweenX function is not looping round? Any pointers...

               

               

              ActionScript Code:
              private function tweenX(event:TweenEvent):void
                      {
                          if(randomXBoundary == 50)
                          {
                              var newRandomXBoundary = randomXBoundary + 950;
                          }
                          else if(randomXBoundary == 1000)
                          {
                              var newRandomXBoundary = randomXBoundary - 950;
                          }
                         
                          myTweenX = new Tween(this, "x", Regular.easeOut, this.x, newRandomXBoundary, 10, true);
                          trace("tweenX function for " + this + " has been called and is heading for" + newRandomXBoundary + " x pos");
                      }//end of tweenX function
              • 4. Re: Smoother Tween alternative to ENTER_FRAME function???
                kglad Adobe Community Professional & MVP

                 

                ActionScript Code:
                import fl.transitions.Tween;
                    import fl.transitions.easing.*;
                    import fl.transitions.TweenEvent;

                myTweenX = new Tween(this, "x", Regular.easeOut, this.x, randomXBoundary, 10, true);
                            myTweenX.addEventListener(TweenEvent.MOTION_FINISH,tweenX);


                private function tweenX(event:TweenEvent):void
                        {
                            if(randomXBoundary == 50)
                            {
                                var newRandomXBoundary = randomXBoundary + 950;
                            }
                            else if(randomXBoundary == 1000)
                            {
                                var newRandomXBoundary = randomXBoundary - 950;
                            }
                           
                            myTweenX = new Tween(this, "x", Regular.easeOut, this.x, newRandomXBoundary, 10, true);           
                myTweenX.addEventListener(TweenEvent.MOTION_FINISH,tweenX);
                trace("tweenX function for " + this + " has been called and is heading for" + newRandomXBoundary + " x pos");
                        }//end of tweenX function