4 Replies Latest reply on Oct 17, 2008 10:22 AM by russ500

    movie clip to follow mouse

      Hi there,

      I'm trying to make an image follow the mouse when the mouse moves on the stage but have the image go back to its central position when the mouse leaves the stage. I would like the image to be a fair bit bigger than the stage so that you don't ever see it all but can see more of it when you move the mouse to the edges of the stage.

      I have had a look around for some tutorials as I know very little about actionscript but have only found one tutorial that is along the lines of what I want to do here. This tutorial uses a small ball but the ball does not go back to the center of the movie when the mouse leaves the movie.

      Does anyone know of a way I can adapt this tutorial to do what I talked about? Please let me know if you need me to explain better.

      Many thanks.
        • 1. Re: movie clip to follow mouse
          clbeech Level 3
          hey russ - getting the bg to pan in relation to the position of the mouse is no problem - but detecting when the mouse is 'not' on the stage kinda is :( BUT only if your using AS2 - AS3 has a new Stage event that is called "mouseLeave" that will fire when this happens. there might be a work around in 2 though (and of course there may be another prop that i don't know about) like for instance, you could be running an onEnterFrame loop to pan and control the movement, well lets say the if you find that the value of _xmouse is the same for a 'long' period of time (using a counter of some sort) you could then 'assume' that the mouse has left the stage, and then initiate the movement back to center. just some thoughts, again though, easier to achieve in AS3 simply because the event is available.
          • 2. Re: movie clip to follow mouse
            russ500 Level 1
            Hey thanks for getting back to me clbeech. Would it make a difference if I make an invisible movieclip the size of the stage and when the mouse leaves that mc that tells the background image_mc to return to its central position. Does that make any sense? Below is the code I am starting with:
            • 3. Re: movie clip to follow mouse
              clbeech Level 3
              np russ :) - yeah that's part of the problem really - the moment the that the mouse leaves the stage, the value of the last know mouse coordinate is the one 'kept' - so it then no longer 'registers' values beyond the stage bounds at all see. so one way may be to use a rollover, rollout on the invisible MC your talking about to trigger the opposing methods rather than using the mouse cooridinates. because the _xmouse will never return a value less than or greater than the bounds of the stage.

              but the above does look like a good start :)
              • 4. Re: movie clip to follow mouse
                russ500 Level 1
                Ah I think I'm with you. I'll have a tinker around and see what I can come up with. Thanks again for your wisdom clbeech.