1 Reply Latest reply on Oct 9, 2010 7:02 AM by kglad

    gotoAndStop Proplem :(

    antworker

      Hello,

      I was given this code:

       

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

       

       

       

      function keyDownF(){
           if(Key.getCode() == 32){
               if (Key.isDown(Key.SPACE))
      gotoAndStop("police_car", 1);
               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;

       

       

      I want my car image I use now to switch to another image called "police_car"

      I tried to use this code:

       

      if (Key.isDown(Key.SPACE))
      gotoAndStop("police_car", 1);

       

       

      When I test my game I get no errors but when I press space nothing happen, it's supposed to switch image when pressing space but nothing happens.

       

        • 1. Re: gotoAndStop Proplem :(
          kglad Adobe Community Professional & MVP

          the most that will do is change frames and the code is problematic even for that simple task.  to change the main timeline from the current frame to a frame labeled "police_car" use:

           

           

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

           

          function keyDownF(){{
                   if (Key.isDown(Key.SPACE)){
          _root.gotoAndStop("police_car");
                   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;