3 Replies Latest reply on Mar 15, 2014 3:11 PM by kglad

    removing tweens

    paul_james123

      Hi All,

      I'm a AS3 learner and have 3 questions:

       

      1.) For optimization purposes, is it recommended that one always removes tweens after they are done? (For example, I'm moving a movie clilp across the stage in three movements with a 1 sec pause inbetween. Should I remove the tween between each of the 3 movements or is that kinda dumb?) Any rule of thumb for when it's not worth it to remove tweens?

       

      2.) If I'm not going to use a tween again in the movie, I assume it's recommended to remove it (as well as the eventlistener attached to that tween and set any associated global variables to 'null). Is this the way to do it?:

      var Tween1:Tween = new Tween(myMovieClip, "x", Back.easeOut, 474.5, 407.5, 2, true);

      Tween1.addEventListener(TweenEvent.MOTION_FINISH, doneMovingMC);

       

      function doneMovingMC (e:TweenEvent):void

      {

          var myTween:Tween = e.currentTarget as Tween;

          myTween.removeEventListener(TweenEvent.MOTION_FINISH, doneMovingMC);

          myTween = null;
      }

       

       

      3.) How can you test to see if it actually worked (removed the tween)?

       

      Thanks much!

        • 1. Re: removing tweens
          kglad Adobe Community Professional & MVP

          that's a good question.

           

          each tween uses about 208 bytes of memory compared to a barebones movieclip that uses 752 bytes of memory.  so, if you had 100 tweens that would use ~ 208 * 100 / 1024 ~ 20.3kb.

           

          and there's no easy way to detect when (of if) any particular object has been removed from memory.  you can use adobe scout to profile your project to see how it handles (among other things) memory as it plays, and you can use some of the System properties (like totalMemory) but that's about as much as you can do.

           

          btw, your myTween is NOT the same as Tween1.  it's just a variable pointing to Tween1.  so, you're NOT making Tween1 eligible for gc with your code.  you would use something like:

           

           

          var Tween1:Tween = new Tween(myMovieClip, "x", Back.easeOut, 474.5, 407.5, 2, true);

          Tween1.addEventListener(TweenEvent.MOTION_FINISH, doneMovingMC);

           

          function doneMovingMC (e:TweenEvent):void

          {

           

          Tween1=null


          }

           

           

          • 2. Re: removing tweens
            paul_james123 Level 1

            Thanks Kglad.

             

            you wrote:

            ...so, you're NOT making Tween1 eligible for gc with your code

            . By "gc" you mean 'garbage collection'?

             

            Thanks for the clarification regarding 'myTween' just being a pointer. I wondered about that.

            • 3. Re: removing tweens
              kglad Adobe Community Professional & MVP

              yes, gc = garbage collection.

               

              (and you're welcome.)