3 Replies Latest reply on Dec 5, 2008 1:50 AM by FunkyGibber

    Please help...Need to rotate image/MC by moving mouse

      Hi all,

      I'm sure a lot of you have seen the tutorials for buttonless scrolling (where you move your cursor to the right of the screen and the movieclip scrolls to the left etc). Here is an excellent example... http://www.gotoandlearn.com/ (and then scroll down until you get to the title, 'Scrolling Thumbnail Panel'.

      Now, I want to use this principle to rotate a MC of the world instead of scrolling the MC left and right. So, as your cursor moves to the right of the screen, the globe rotates in an anti-clockwise direction and visa versa.

      Could anyone help moderate the code below (or provide new code) to make this work? I've tried a few things but none of them work. Thanks!! (Really need this for campaign at work!! Panicking a bit).


      the code...

      panel.onRollOver = panelOver;

      function panelOver() {
      this.onEnterFrame = scrollPanel;
      delete this.onRollOver;

      var b = stroke.getBounds(_root);

      function scrollPanel() {
      if(_xmouse<b.xMin || _xmouse>b.xMax || _ymouse<b.yMin || _ymouse>b.yMax) {
      this.onRollOver = panelOver;
      delete this.onEnterFrame;

      if(panel._x >= 89) {
      panel._x = 89;

      if(panel._x <= -751) {
      panel._x = -751;

      var xdist = _xmouse - 250;

      panel._x += Math.round(-xdist / 7);
        • 1. Re: Please help...Need to rotate image/MC by moving mouse
          FunkyGibber Level 1
          OK, I've got a script that is a lot easier and DOES rotate the m/c! It's:

          var mouseList:Object = {};
          mouseList.onMouseMove = function(){
          worldMC._rotation = _xmouse;

          But it stops when my cursor does. In the scrolling example, the further right your cursor goes, the more the horizontal MC scrolls. Only when the cursor is in the centre of the screen does the globe stop rotating.

          So what I really need here is a globe that starts to rotate anti-clockwise when the cursor is moved to the right...the further right it goes, the faster it rotates. When the cursor moves to a central location, the speed of the globe's rotation slows to a stop (allowing the user to click onto a point on the globe).

          If you've given the example I linked to above a go, this should be a little clearer. It's hard to put into writing, but I hope you get the idea. Looking forward to hearing from you.

          • 2. Re: Please help...Need to rotate image/MC by moving mouse
            clbeech Level 3
            one way of doing this is to 'measure' the distance from the center point of the globe to the mouse position - divide by the 'total' distance available within your range of movement, resulting in a percentage. then apply the percentage to a constant you declare like 'speed' which would be the max rate of rotation. in this way you will decrease the speed the closer you are to the globe. you can even put in a buffer so that when you are within a certain range of the center it will slow to zero.
            • 3. Re: Please help...Need to rotate image/MC by moving mouse
              FunkyGibber Level 1
              Thanks for the reply. I have the code that makes this work perfectly...just in case anyone else need it, it's:

              onEnterFrame = update;

              function update():Void
              worldMC._rotation += ( Stage.width / 2 - _xmouse ) / 20;