10 Replies Latest reply on May 26, 2008 9:25 AM by clbeech

    Moving Movie Clips with Arrow keys

    privatedan
      How do i make it so when i click the left arrow key, it will change the movie clip to make it turn around?
        • 1. Moving Movie Clips with Arrow keys
          Ned Murphy Adobe Community Professional & MVP
          I'm not sure what you intend by "turn around", but here's how to make the left key produce action
          • 2. Moving Movie Clips with Arrow keys
            privatedan Level 1
            When i say turn around i mean, make the movie clip rotate so it faces the other way. When i use the left arrow key it makes it look like its doing the moon walk. Do you know the way to make it do that, or do i have to make it go to another frame or something.
            P.S. i copied and pasted what was above into my Flash Actions. When i tested the movie and pressed left arrow the output box popped up and said "you're pressing the left arrow"
            • 3. Re: Moving Movie Clips with Arrow keys
              Ned Murphy Adobe Community Professional & MVP
              Yes, that's what the code I gave you is intended to do.... you replace that code with whatever action you need to take to turn your movie around.

              I have no idea what your movieclip is doing, but I'm guessing by your response that if it was an arrow pointing left to right (just an example), you want it to be pointing right to left when the left arrow is pressed. If you want an immediate turn around, then the simplest way to do that is to have another frame containing the movieclip that it moves to where it faces the other direction--and to have it appear turned around, from the toolbar you select Modify -> Transform -> Flip Horizontal.

              So the movieclip would live inside another movieclip that has two frames with stop()'s for each frame. In the first frame you would have the subclip facing left to right, and in the second you would have it facing right to left. If we call that 2-framed movieclip "walker", the code I provided before would become...
              • 4. Re: Moving Movie Clips with Arrow keys
                clbeech Level 3
                hey guys a great way to do this without constructing another physical frame or position is to use:

                walker._xscale = -100;

                then flip it back when the right arrow is pressed:

                walker._xscale = 100;
                • 5. Moving Movie Clips with Arrow keys
                  clbeech Level 3
                  another suggestion here is to use an onEnterFrame loop to capture key input - because the Key handler in this case will only be invoked on each press of the key, creating a non-fluid movement for the character - while using a looping script will continue to pick up the input as long as the key is depressed. it would look something like this:
                  • 6. Re: Moving Movie Clips with Arrow keys
                    Ned Murphy Adobe Community Professional & MVP
                    Thanks, Chris... I was trying to think of a coded way of doing it, but reverted to my timeline background for my answer.
                    • 7. Re: Moving Movie Clips with Arrow keys
                      privatedan Level 1
                      Has helped alot, Ned the thing i'm trying to move is a man running so its more of a 5 frame movieclip. When i did beech's script it turned it around but stopped on the first frame. I have put the movie clip so it turns half way through and included the stop(); but i want to make the first part of the clip play the animation over and over so it looks like he's running (loop) and move when you press the right then the second part to play the animation over and over(loop) when i hit left arrow key
                      • 8. Re: Moving Movie Clips with Arrow keys
                        clbeech Level 3
                        ok - assuming that the first frame is the 'standing' image place a stop() there on the first frame. add a control variable on the root timeline, then on the last frame place a condition to determine if the character should continue the animation cycle (you may need to add an additional position to make the transition look smooth) then in the scripts call the character to play() - then add another Key condition that asks if NO Keys are currently being used then assign the var to false and the character will move to the standing position at the end of the cycle - more like this:

                        PS. np Ned lol! ;)
                        • 9. Re: Moving Movie Clips with Arrow keys
                          privatedan Level 1
                          Thank you SOOO much it is working great, one thing is though, after i start walking and then let go of the arrow key it keeps on going in that loop of running. Even though at first it is standing still. Not to concerned about it but if you know tell me please :D. If not don't worry you've helped me alot!
                          • 10. Re: Moving Movie Clips with Arrow keys
                            clbeech Level 3
                            LOL! you're welcome :)

                            well in the above - it will continue to the end of the cycle before stopping, I usually do it this way in order to make the animation 'complete' it motion - however you could 'jump' to the standing position at anytime the key is released by doing away with the 'second' part (eg. 'else') of the conditional statement in the walker clip - and calling the gotoAndStop(1) from within the 'release' (ie. the 'third') condition in the onEnterFrame handler. he would then instantly stop and goto standing when the key is released.