5 Replies Latest reply on Nov 13, 2010 3:30 PM by Ned Murphy

    Is this possible?

    unamus3d

      I have a movieclip which i will tween inside. The startframe of the tween will be X for example and the end will be the Center of the Screen.

       

      is there anyway i can achieve this so the tween ends in the middle of the sreen no matter where the movie clip is placed.

       

      thanks.

        • 1. Re: Is this possible?
          Ned Murphy Adobe Community Professional & MVP

          You can do it using actionscript for the tweens.  Below demos one approach using Flash's built-in Tween class.  There are really only four lines of code you need to pay attention to, which I have bolded, the rest is just for demo's sake.  Open a new file and create a movieclip on the stage and give it a name "mc".  Then put the fllowing code in the same frame on a different layer.

           

          import mx.transitions.Tween;
          import mx.transitions.easing.Regular;

           

          mc.onRelease = tweenMC;

           

          function tweenMC(){
              mc._x = Math.random()*Stage.width;
              mc._y = Math.random()*Stage.height;
              var twX = new Tween(mc, "_x", Regular.easeIn, mc._x, Stage.width/2, 1, true);
              var twY = new Tween(mc, "_y", Regular.easeIn, mc._y, Stage.height/2, 1, true);
          }

           

          Each time you click the mc it will find a random place on the stage and then tween to the center.  In the tween code, it intiates the tween at the current location of the mc (mc._x/mc._y) and ends it at center stage.

          • 2. Re: Is this possible?
            NikolaV97

            Heh, its fun, i added the simple drag-drop function to the mc and ended up with a simple mini-app, you can drag the ball, but it will come back to the center...

             

            btw: you entered 'easeIn', what types of these, what ever they are, are there? i changed it to easeOut and came with a bit smoother animation...

            • 3. Re: Is this possible?
              Ned Murphy Adobe Community Professional & MVP

              To make it a little more fun, you can add a bounce to it...

               

              import mx.transitions.Tween;
              import mx.transitions.easing.Elastic;

               

              mc.onRelease = tweenMC;

               

              function tweenMC(){
                  mc._x = Math.random()*Stage.width;
                  mc._y = Math.random()*Stage.height;
                  var twX = new Tween(mc, "_x", Elastic.easeOut, mc._x, Stage.width/2, 1, true);
                  var twY = new Tween(mc, "_y", Elastic.easeOut, mc._y, Stage.height/2, 1, true);
              }

              1 person found this helpful
              • 4. Re: Is this possible?
                unamus3d Level 1

                Thank you for the reply not quite what im looking for, i meant shape tween, as in.

                i have say a 'dot/small line' and i want that dot to 'stretch/grow' [shape tween] into a line t'wards the center of the screen.

                 

                this is what i meant when i was askin g is it possible.

                • 5. Re: Is this possible?
                  Ned Murphy Adobe Community Professional & MVP

                  You're welcome.  The new version of your story doesn't at all resemble what you were asking in your original posting.  For an example of the amount of coding you might have to do to implement dynamic shape tweening you can visit the posting linked below.  I can't say you will get anywhere with it though, I know I wouldn't.

                   

                  http://forums.adobe.com/thread/750269?tstart=30

                   

                  That code will not address your desire to have things tend to the center of the stage.

                  1 person found this helpful