4 Replies Latest reply on Oct 12, 2010 5:25 AM by srirama.83

    Play movie/frame when key is pressed?

    antworker

      Hello,
      I have a car that is a movieclip with 2 frames looping in scene 1 and I  want the car to switch to another movieclip when I press the space  button and go back to the oroginal car clip when space is released and  if possible add a sound when space is pressed.
      Thank you.

        • 1. Re: Play movie/frame when key is pressed?
          Ned Murphy Adobe Community Professional & MVP

          Here's some code for the keyboard controls...

           

          var keyListener:Object = new Object();
          Key.addListener(keyListener);

           

          function keyDownF(){
               if(Key.getCode() == 32){ 
                   // put switch to other clip code here
                   delete keyListener.onKeyDown; // to avoid repeating this function while key is down
               }
          }

           

          keyListener.onKeyDown = keyDownF;

           

          function keyUpF(){
               if(Key.getCode() == 32){ 
                   // put code to go back to car clip here
                   keyListener.onKeyDown = keyDownF; // to restore the press interaction
               }
          }

           

          keyListener.onKeyUp = keyUpF;

          • 2. Re: Play movie/frame when key is pressed?
            antworker Level 1

            I'm sorry im a bit slow to understand that, but let's say that i want the original car which name is "car" to switch with another movieclip named "car_shoot" should I just put the text "car_shoot" and replace it were it says " // put switch to other clip code here" ? (Beginner )

            Thank you anyway.

            • 3. Re: Play movie/frame when key is pressed?
              Ned Murphy Adobe Community Professional & MVP

              Yes, besically that's what you need to do... replace that line with whatever you intend.   I have no idea what you intend/mean as far as switching movieclips, so how you do that is up to you.

              1 person found this helpful
              • 4. Re: Play movie/frame when key is pressed?
                srirama.83

                You can also achieve this by having 2 frames in the car movieclip , first frame one car and second frame other

                then modifying the earlier code given u can write

                 

                // put switch to other clip code here

                car_mc.gotoAndStop(2)

                 

                // put code to go back to car clip here

                car_mc.gotoAndStop(1)

                 

                considering ca_mc is ur movieclip hope this is what you are looking at.