8 Replies Latest reply on Sep 21, 2009 10:22 AM by videostart

    Rotating through frames via the mouse

    videostart Level 1

      I am working on an animation that I need to rotate in flash, via the mouse?

       

      Is there a way to cycle through the frames left and right via the movement of the mouse?

        • 1. Re: Rotating through frames via the mouse
          Ned Murphy Adobe Community Professional & MVP

          You can have an enterframe event/function constantly checking the current posiition of the mouse to the last position of the mouse to determine what direction it is moving and somehow make use of that to move to different frames.

          • 2. Re: Rotating through frames via the mouse
            videostart Level 1

            I've been playing with this script but it is rotating the entire movie clip instead of running through the frames.

             

            Can this somehow be modified to run through the frames instead of rotating the clip?

             

            var radiance:Number = 180/Math.PI;

             

            //movieclips array

            var clipsArray:Array = ["building_mc"];

             

             

            /**

            • Main Loop

            */

            _root.onEnterFrame = function()

            {

                 //loop through clipsArray

                 for(var i = 0; i < clipsArray.length; i++)

                 {

                      //set temp movieclip

                      var tempClip:MovieClip = eval(clipsArray+);

                      //calculate rotation

                      walkdirection = -(Math.atan2(_xmouse-tempClip._x, ymouse-tempClip.y))*radiance;

                      //set rotation

                      tempClip._rotation = walkdirection;

                 }

            }

            stop();

            • 3. Re: Rotating through frames via the mouse
              Ned Murphy Adobe Community Professional & MVP

              I wouldn't say it can be modified, more like scrapped except for a few lines...

               

              _root.onEnterFrame = function()

              {

                   // this stuff can go

              }

               

              That whole bit of code is based on rotaing things.  What you want to do is keep is keep track of the mouse position (I'll assume you intend horizonal mouse movement)

               

              stop();

               

              var lastPosition = _xmouse;

               

              _root.onEnterFrame = function()

              {

                   if(_xmouse > lastPosition){

                        // some mc's direction of frame movement?

                   } else if(_xmouse < lastPosition){

                        // some mc's opposite direction of frame movement?

                   }

              }

               

              For that example, I use < and > because == would be the case where the mouse hasn't moved, and I assume no movement means no frame changing.

              1 person found this helpful
              • 4. Re: Rotating through frames via the mouse
                videostart Level 1

                Ok, I plugged in your code below:

                 

                stop();

                 

                var lastPosition = _xmouse;

                trace(lastPosition)

                 

                _root.onEnterFrame = function()

                {

                     if(_xmouse > lastPosition){

                          building_mc.stop();

                     } else if(_xmouse < lastPosition){

                          building_mc.stop();

                     }

                }

                 

                 

                I tried playing with adding building_mc.stop(); and building_mc.play();

                 

                But as soon as I start the movie, the animation just plays continuously with both.

                If I add the stop code as soon as I move the mouse it stops, but if I add the play

                Code it doesn't do anything when I move the mouse.

                 

                I traced last Position when I start the movie, it picks up the position...?

                • 5. Re: Rotating through frames via the mouse
                  Ned Murphy Adobe Community Professional & MVP

                  I don't know what your intentions of control are, but I didn't think they were simply play() and stop() of a timeline.  That kind of control doesn't really warrant having an enterframe function at play... something more of a rollover and rollout of some object would be simpler.

                   

                  In any case, for the code I showed I forgot to include the one line that updates the lastPosition everytime the enterframe function processes.

                   

                  I've created an example that demonstrates using the mouse direction of travel to control one's position on the timeline of a movieclip.  I saved it as a Flash 8 file, so hopefully you can access it...

                   

                  http://www.nedwebs.com/Flash/AS2_Mouse_Control.fla

                   

                  Even if this isn't what you want, you should be able to adapt it to what you are really after.

                  1 person found this helpful
                  • 6. Re: Rotating through frames via the mouse
                    videostart Level 1

                    Great example.  Definitely closer to what I'm trying to do.  Ultimately, I'd like it to function like this example I saw online:  http://flashden.net/item/vr-360-inside-build-360-degree-3d-objects-from-a-series-of-still- images/28226

                     

                    I plugged in my mc with your coding example.  It rotates when I move the mouse to the right, but then it stops at the end of the animation.  I don't have a stop action at the end of my animation.  I tried putting a gotoAndPlay(1) at the end of the animation so it starts over again, but that didn't work. 

                     

                    When I move the mouse to the left it goes very very slowly and the mouse runs off the screen before it does a full rotation.  There are 120 frames in my animation.  So is there a way to scroll through them quicker than just using nextFrame?

                    • 7. Re: Rotating through frames via the mouse
                      Ned Murphy Adobe Community Professional & MVP

                      The example I gave only uses direction to manage the change of frames, so it is independent of the distance you move the mouse and the time you take to do it.  What you will want to do is pull in the actual distance the mouse has moved as well (_xmouse minus lastPosition).  And then you want to equate some amount of distance change to some amount of frames to move.  The example you pointed to has a difference in that it uses the pressing down event to initiate the movement engine, which essentially sets the lastPosition intial value each time.

                       

                      So you want to figure out how to work in the number of frames to move based on the distance you move the mouse.  In your example it appears as though they get a few full rotations if you move across the whole stage, so you want to decide how your 120 frames relates to x-number of pixels moved.   What follows is not a definitive solution, just an example of how the code would change from what I offered before.  You'll have to work in the factors for how far to move in frames per how far the mouse has moved (_xmouse - lastPosition)... As for looping the rotation, you probably need to check each time before you moved to see if you are going to either exceed frame 0 (going left) or 120 (going right) and adjust the value of the gotoAndStop accordingly.

                       

                      _root.onEnterFrame = function()
                      {
                      mc.gotoAndStop(mc._currentframe + (_xmouse - lastPosition));
                      lastPosition = _xmouse;
                      }

                       

                      I gotta stop now... I almost got shut down in this message and don't wanna chance it happening again.

                      • 8. Re: Rotating through frames via the mouse
                        videostart Level 1

                        Thanks for the explaination, u almost got shut down?