3 Replies Latest reply on Jul 20, 2012 1:22 PM by Ned Murphy

    go to specific location

    alaStickman Level 1

      hello,

      if i have a movie clip with those X,Y cordinate (100,100) and i want him to go to (300,200) but i want to see him "walking" till he reach the location with a constant speed .

      how can i do it ?

       

      thank you

        • 1. Re: go to specific location
          Ned Murphy Adobe Community Professional & MVP

          There are a couple ways you can move an object using actionscript. 

           

          One is to use the Tween class or a third party tweening class such as Tweenlite. 

           

          Another is to use enterFrame processing to have the object's _X and _y coordinates gradually increase to the final values at constant increments (in the sample code below "yourMC would be replaced with the instance name of your movieclip).

           

          var stepsize = 2; // adjust as desired for speed

           

          this.onEnterFrame = function(){

               if(yourMC._x >= 300){

                     delete this.onEnterFrame;

               } else {

                     yourMC._x += 2*stepsize;

                     yourMC._y += stepsize;

               }

          }

           

          As far as the walking goes, you would need to have the movieclip do the animation of the stepping.

          • 2. Re: go to specific location
            alaStickman Level 1

            thank you it's exactly what i need

            about this :

            " delete this.onEnterFrame;"

            it mean that if the condition is correct then stop running the function ??

            thank you again

            • 3. Re: go to specific location
              Ned Murphy Adobe Community Professional & MVP

              Yes, in this case if the value of x is equal or greater than the final value (300) then that line of code will stop the enterframe function from working.