9 Replies Latest reply on Jun 15, 2006 3:27 PM by Craig Grummitt

    Moving an mc to mouse coord's

    Jimmathy Level 1
      ill admitt it, i am a complete novice when it comes to actionscript, but the best way i found to learn it is to get the code and change each part to figure it out. So how would i make it so that when i click Either on a mc or just anywhere that it creates an mc at coodinants that ill specify and makes it move pretty quicky to the mouse coordinant where the mouse was clicked.
      thanks
        • 1. Re: Moving an mc to mouse coord's
          kglad Adobe Community Professional & MVP
          it wouldn't make sense to create a movieclip and have it move towards the mouse because you can only create an empty movieclip which wouldn't present much visual excitement for the viewer. you could attach a movieclip from your library and have it move towards the cursor.

          if that's what you want you need to create the movieclip in the authoring environment (or load a swf or use the drawing api), enable its export for actionscript and then attach it someplace when the mouse is pressed. you can then initiate a loop that would move the movieclip from where it was attached to the cursor.
          • 2. Re: Moving an mc to mouse coord's
            Jimmathy Level 1
            Okay, i figured out a better way to go about this, so forget about the attachmovie part. Now what i cannot figure out is how to make an mc that is placed on the stage move to the mouses coordinates where it was clicked, then make it's _x _y coordinates the original ones from when it was placed on the stage after about 2 seconds of moving to the mouses position.
            thanks
            • 3. Re: Moving an mc to mouse coord's
              kglad Adobe Community Professional & MVP
              i understand the part about the mc moving to the spot on-stage where the mouse was pressed. what's that second part about making something's "... _x_y coordinates the original..."?
              • 4. Re: Moving an mc to mouse coord's
                Jimmathy Level 1
                in other words i mean i want the mc to "warp" back to where it started. but I want it to warp after about .24 seconds of traveling towards the mouse's x/y.
                so, the user clicks, the mc begins to move towards the coordinates of the mouse click, and after .24 seconds the mc goes back to the position that it began in.(in the last post i messed up and said 2 seconds but i meant .24 sec)

                thanks
                • 5. Re: Moving an mc to mouse coord's
                  kglad Adobe Community Professional & MVP
                  oh. i'm not sure that will look good, but:

                  • 6. Re: Moving an mc to mouse coord's
                    Craig Grummitt Level 3
                    couldn't resist the challenge! I'm not sure what 'warp' means but you could also use the tween class to achieve this. kglad's code may be better as it will work for you independent of the frame rate(you would want to up the frame rate to get a smoother animation), however using tween does give you access to preset easing classes and methods if you need them.
                    • 7. Re: Moving an mc to mouse coord's
                      Jimmathy Level 1
                      well, after thinking about what i was doing,i've decided that i was being retarded andi have no clue of how i came up with the "warp" solution. so i have finally decided that the best way to do this. i will have a blank movie clip at the bottom of the stage, when a user clicks anywhere on the stage, an mc of a ketchup packet will then be attached to that blank mc, the ketchup will then move to the mouse click. I know how to do the attaching part, but i still cannot quite figure out how to make the packet(or any mc for that matter) to move to the _xmouse and _ymouse of a click.

                      also grummitt, i'm guessing that your code is for flash 8 because of the tween easing and the fact that my flash didnt recognize a property. i have mx 2004 but thanks anyway.

                      thanks
                      • 8. Re: Moving an mc to mouse coord's
                        Jimmathy Level 1
                        never mind i figured it out thanks alot!!!


                        thanks
                        • 9. Re: Moving an mc to mouse coord's
                          Craig Grummitt Level 3
                          yes the tween class was introduced in flash 8.