5 Replies Latest reply on Aug 3, 2007 11:52 AM by Rothrock

    Prevent Enter key from proceeding movie

    Denatram
      I am using this code to get the user to enter the answer 16 in an input text field. It works but if the user hits the enterkey after they've gotten the question right, the playhead starts and moves to incorrect. This is not happening only in the testing environment, the published file continues when Enter is pressed. Can anyone help?

      keyListener = new Object();
      keyListener.onKeyUp = function() {
      if (input_txt2.text == "16" and Key.getCode() == 13) {
      //13 is key code for 'Enter'//
      gotoAndPlay("1_3_13a");
      _root.answer1 = "Correct!";
      } else if (input_txt2.text != "16" and Key.getCode() == 13) {
      //13 is key code for 'Enter'//
      _root.answer1 = "Incorrect.";
      gotoAndPlay("1_3_13b");
      }
      };
      Key.addListener(keyListener);
        • 1. Re: Prevent Enter key from proceeding movie
          Rothrock Level 5
          Enter key only proceeds the moving in the testing environment. Try it in an html page or projector and you should be fine. But if you do need to test in the testing environment – and who doesn't – go up to the control menu in the testing environment and make sure to check disable keyboard shortcuts. Of course you won't be able to use short cuts like apple-w to close the testing window, but that is the price you pay.
          • 2. Re: Prevent Enter key from proceeding movie
            Denatram Level 1
            Thanks Rothrock,
            I did try publishing to html and the issue is still there. It exists in the file when played in a Saba Publisher/Lectora executable as well.
            I am no genius programmer, so is there another way to write this code? It seems the code below is activated when the enter key is pressed even after the event has occured.

            } else if (input_txt2.text != "16" and Key.getCode() == 13) {
            //13 is key code for 'Enter'//
            _root.answer1 = "Incorrect.";
            gotoAndPlay("1_3_13b");
            }

            • 3. Re: Prevent Enter key from proceeding movie
              Rothrock Level 5
              I'm not following what "…activated when the enter key is pressed even after the event has occurred." means. You mean that even after this first entry you press enter and the value of input_txt2.text != "16" so it is jumping to 1_3_13B?

              I think I know what you mean, maybe. Notice how you are setting up a listener? Well it keeps listening, it isn't a one time deal. It listens for a keyUp until you tell it to stop. So just because it works once why would you expect it to stop working? :)

              What you need to do is either inside your conditionals or perhaps just inside the onKeyUp function put a Key.removeListener(keyListener); to tell it to stop listening. If you are doing some kind of remediation at 1_3_13b and then want them to have another try, perhaps you will want to leave the listener or you might want to remove it and then add it back. I don't know the exact structure of what you are doing, but I hope this points you in the correct direction.
              • 4. Re: Prevent Enter key from proceeding movie
                Denatram Level 1
                I thought the same thing. I have tried to put in the Key.removeListener(keyListener); but I may not have placed correctly. I'll keep trying that.
                Thanks.
                • 5. Re: Prevent Enter key from proceeding movie
                  Rothrock Level 5
                  Not sure, but anytime you need to you could do this:

                  for(var a in Key._listeners){
                  trace(a+" is "+Key._listeners[a]);
                  }

                  That will show you a list of everything that is listening for the Key events and perhaps you can pin down what is listening.