5 Replies Latest reply on Aug 19, 2009 10:36 AM by NSurveyor

    Globe Rotation script?

    surfmad1 Level 1

      Hi, I've created a 2D globe in Flash which automatically rotates clockwise very slowly using actionscript. On the globe there are sign posts which rotate with the globe, each sign post will link to another url. I would like to allow the user to spin the globe faster when they click the left mouse button while moving the mouse in a downward motion but once they've spun the globe faster it should then gently slow back down to its original speed.

       

      Could anyone advise me on the code I need to achieve this or maybe direct me to an online tutorial.

       

      Many thanks

        • 1. Re: Globe Rotation script?
          NSurveyor Level 2

          I'm not sure if this is what you're after, but have a circular MovieClip with it's registration point at the centre, named globe_mc. Then, p;lace the following script on the frame:

           

          globe_mc.iav = 1; // initial angular velocity
          globe_mc.aav = 0; // additional angular velocity
          globe_mc.d = .99; // rate of decay of aav
          // Spin
          globe_mc.id = setInterval(spin,10,globe_mc);
          // When mouse is clicked, moved, and released,
          // keep track of changes in _ymouse and timer 
          // to determine the vertical velocity of the mouse.
          globe_mc.onPress  = function(){
           this.ny = this._parent._ymouse;
           this.nt = getTimer();
           this.onMouseMove = function(){
            this.oy = this.ny;
            this.ot = this.nt;
            this.ny = this._parent._ymouse;
            this.nt = getTimer();
            this.onMouseUp = function(){
             // These will be redefined when the globe is clicked again
             delete this.onMouseMove;
             delete this.onMouseUp;
             // Let the additional angular velocity of the globe
             // increase proportionally to the vertical velocity of the mouse.
             // This equates to: 'pull harder, spin more'.
             this.aav += 5*(this.ny-this.oy)/(this.nt-this.ot);
            }
           }
          }
          //Spin function based on initial/additional angular velocity and decay.
          function spin(mc){
           mc._rotation += mc.iav + mc.aav;
           mc.av *= mc.d;
          }
          
          • 2. Re: Globe Rotation script?
            surfmad1 Level 1

            Hi Nsurveyor, that's almost perfect!!!

             

            The problem is when I test the movie and spin the globe it spins too quickly when I click and drag 3 or 4 times, the 'globe_mc' probably needs a maximum spin rate to prevent it from rotating too quickly. Also the movie clip doesn't slow down to a really slow rotation once I've lifted the mouse button it just carries on spinning quickly.

             

            If you can help me any further it would be very much appreciated!

             

            many thanks

            • 3. Re: Globe Rotation script?
              NSurveyor Level 2

              Whoops, there was a typo that prevented the globe from slowing. The last line should read:

              mc.aav *= mc.d;
              

              With that in place, I think the maximum speed will not be an issue. Note, you can have the user's pull be more effective, by changing the constant of proportionality, in the line:

              this.aav += 5*(this.ny-this.oy)/(this.nt-this.ot);
              

              in which a number larger than 5 would cause such an effect. nd lastly, the (exponential) rate at which it slows down is determined by globe_mc.d in the line:

              globe_mc.d = .99; // rate of decay of aav
              

              Bringing this value closer to zero, will make the globe slow down almost immediately, while a value closer to 1 will let the globe slow down very slowly.

               

              Hope that helps.

              1 person found this helpful
              • 4. Re: Globe Rotation script?
                surfmad1 Level 1

                Perfect!!

                 

                Thank you so so much

                • 5. Re: Globe Rotation script?
                  NSurveyor Level 2

                  You're welcome.