10 Replies Latest reply on Feb 11, 2007 11:00 AM by Peter Lorent

    MX Tween classes and endTween():Void

    AKIRA_x
      I have had to use MX tween classes for a project. Later into the project the need for a skip button was introduced. But as we know once a tween has started it will run no matter what. So I need to interrupt the tween and make it skip to the end. I googled and found the endTween function. but I am having trouble making it work. As I understand the function its supposed to make my tweens skip to the end and be done. But I am not having any luck. I have made a test code and could really use some help!

      quote:

      import mx.transitions.Tween;
      import mx.transitions.easing.*;

      var square:Object = new Tween(square_mc, "_x", Regular.easeOut, 0, 451, 5, true);


      And I try to make this tween skip to the end with a button. I have tried with alot of different configurations. None of them work. This one here is just the last. But it dosent work either as stated:

      quote:

      btn_1.onRelease = function(){
      trace("button works");
      endTween(square_mc);
      }
        • 1. Re: MX Tween classes and endTween():Void
          Peter Lorent Level 2
          btn_1.onRelease = function(){
          trace("button works");
          square.fforward();
          }

          There is no method endTween() available in the Tween Class.
          • 2. Re: MX Tween classes and endTween():Void
            AKIRA_x Level 1
            Sweet!! That did the trick!

            Thank you for the help!!

            AKIRA
            • 3. Re: MX Tween classes and endTween():Void
              AKIRA_x Level 1
              Yeah...I was a bit quick there. That code worked on the test, but not in the project. It has no effect at all actually.

              I got this other code in another forum:

              import mx.transitions.Tween;
              import mx.transitions.easing.*;

              var square:Tween = new Tween(square_mc, "_x", Regular.easeOut, 0, 451, 5, true);

              function endTween(ob) {
              removeMovieClip(__OnEnterFrameBeacon);
              ob.obj[ob.prop] = ob.change;
              }

              btn_1.onRelease = function() {
              trace("button works");
              endTween(square);
              };

              And again it works on the test, but in the project it makes the tween stop where it is when I click the button. So in the test it makes it skip to the end of the tween, but in the project it just freezes the tween. strange....

              AKIRA
              • 4. Re: MX Tween classes and endTween():Void
                Peter Lorent Level 2
                What's the code in the project?
                • 5. Re: MX Tween classes and endTween():Void
                  AKIRA_x Level 1
                  Here is how the code is in the project. Maybe you can see the problem:

                  UPDATE: From Kirupa forum I got the tip of declaring the variables outside the function, and so far that seems to to the trick!! It looks like its working now. Just ironing out some other bugs..but this seems to work. but under here is the code as it was. Next post will have the new code.

                  [code]function build_page(){

                  var heading_tween:Object = new Tween(heading_container_mc.heading_mc, "_y", Strong.easeOut, -14.5, 28, 35, true);

                  var menu_tween:Object = new Tween(menu_txt_mc, "_alpha", Regular.easeOut, 0, 100, 5, true);

                  var kunde_tween:Object = new Tween(kundecase_mc, "_alpha", Regular.easeOut, 0, 100, 10, true);

                  meny_mc.play();

                  trace("Siden er bygget");

                  }



                  function endTween(ob) {

                  trace("endTween running");

                  removeMovieClip(__OnEnterFrameBeacon);

                  ob.obj[ob.prop] = ob.change;

                  }



                  function skip_intro(){

                  endTween(heading_tween);

                  endTween(menu_tween);

                  endTween(kunde_tween);

                  trace("nå prøver vi å skippe");

                  }[/code]



                  AKIRA
                  • 6. Re: MX Tween classes and endTween():Void
                    AKIRA_x Level 1
                    The code that works:

                    var heading_tween:Object;
                    var menu_tween:Object;
                    var kunde_tween:Object;

                    function build_page(){
                    heading_tween = new Tween(heading_container_mc.heading_mc, "_y", Strong.easeOut, -14.5, 28, 35, true);
                    menu_tween = new Tween(menu_txt_mc, "_alpha", Regular.easeOut, 0, 100, 5, true);
                    kunde_tween = new Tween(kundecase_mc, "_alpha", Regular.easeOut, 0, 100, 10, true);
                    meny_mc.play();
                    trace("Siden er bygget");
                    }

                    function endTween(ob) {
                    trace("endTween running");
                    removeMovieClip(__OnEnterFrameBeacon);
                    ob.obj[ob.prop] = ob.change;
                    }

                    function skip_intro(){
                    endTween(heading_tween);
                    endTween(menu_tween);
                    endTween(kunde_tween);
                    trace("nå prøver vi å skippe");
                    }

                    AKIRA
                    • 7. Re: MX Tween classes and endTween():Void
                      Peter Lorent Level 2
                      If you declare var heading_tween inside a function, the variable is local to the function and automatically deleted after the function exits. When you then call endTween(heading_tween); in the function skip_intro(), there is no reference to heading_tween. A trace in the function endTween() would have told you that.
                      function endTween(ob) {
                      trace(ob);
                      trace("endTween running");
                      removeMovieClip(__OnEnterFrameBeacon);
                      ob.obj[ob.prop] = ob.change;
                      }

                      When you declare var heading_tween outside of a function (on a timeline of a movieclip and called 'a timeline var') the variable won't get deleted and you can reference it from your code. That's why the code works now.
                      • 8. Re: MX Tween classes and endTween():Void
                        Peter Lorent Level 2
                        You can also rewind the tween. And use fforward() instead of change.

                        • 9. Re: MX Tween classes and endTween():Void
                          AKIRA_x Level 1
                          Thanks for great input!!

                          I am not a hardcore programer but I do enjoys this part of flash more and more. And a day you learn something new is a good day indeed!

                          AKIRA
                          • 10. Re: MX Tween classes and endTween():Void
                            Peter Lorent Level 2
                            You're welcome.