7 Replies Latest reply on Aug 8, 2010 9:25 PM by kglad

    "Exit" in director is ? in Flash

    Chemistry guy Level 1

      Another in my series of "switching from Director to Flash" questions.

       

      Here's what I'm trying to do.

       

      1. Allow the user to type a new in an Input Text box.

      2. If the number is from 1 to 12, go to the "input" frame

      3. If the number is not from 1 to 12, tell them to type a number from 1 to 12 and give them another chance.

       

      Here's the problem. If the user types a anything that is not a number from 1 to 12, when they try again and type a number from 1 to 12, the Input Text box is cleared, and program does not advance to the "input" frame. I'm guessing that I need to exit the If/Else. In Director, I'd type "exit". What do I do for Flash?

       

      txt_defNumber.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown)

       

      var Term = ""
      var Definition = ""

       

      function reportKeyDown(event:KeyboardEvent):void {   
      if (event.keyCode == Keyboard.ENTER)  {         
         
          var gNumber = txt_defNumber.text;
        
          if (gNumber == "1") {
              Term = "value"
              Definition = "A number and unit that together represent the result of a measurement or calculation, e.g. 100 meters."
              gotoAndPlay("input");
          } else if (gNumber == "2")  {
              Term = "unit"
              Definition = "A defined quantity based on a standard, e.g. meter."
              gotoAndPlay("input");
          } else {
              txt_incorrect_number.text = "Please type a number from 1 to 12."

                //What goes here?
          }
         
      }
      }

        • 1. Re: "Exit" in director is ? in Flash
          kglad Adobe Community Professional & MVP

          use:

           


           

          txt_defNumber.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown)

           

          var Term = ""
          var Definition = ""

           

          function reportKeyDown(event:KeyboardEvent):void {
              if (event.keyCode==Keyboard.ENTER) {

                  var gNumber=Number(txt_defNumber.text);

                  if(gNumber>=1 && gNumber<=12){
                      gotoAndPlay("input");
                  } else {
                      txt_incorrect_number.text="Please type a number from 1 to 12.";

                  }//What goes here?
              }

          }
          • 2. Re: "Exit" in director is ? in Flash
            Chemistry guy Level 1

            I didn't state my question clearly. It's probably because I don't speak "Flash" well. I'll try to simplify it.

             

            The following is a simplified version of my if/else routine. (I want gNumber to be a string variable.)

             

                if (gNumber == "1") {
                    gotoAndPlay("input");
                   } else {
                    txt_incorrect_number.text = "Please type the number 1."
                }

             

            If the user types something other than 1, I want them to be able to try again. That's not working, so I think I need to be able to exit from the if/else routine. In Director, I would add "exit" at the end of the routine. What do I do for Flash?

            • 3. Re: "Exit" in director is ? in Flash
              kglad Adobe Community Professional & MVP

              what you stated in your first message and 2nd message are both clear.  they're both different so i don't know which, if either, you really want.

               

              but if you want what you stated in your first message, use the code i suggested.  if you want what you stated in your 2nd message, your code would work.

              • 4. Re: "Exit" in director is ? in Flash
                Chemistry guy Level 1

                I know the code works the first time. My problem is that I want the user to be able to try again if they have not input a number in the correct range, but when the correct number is put in after the first number input was not in the correct range, the computer doesn't treat it the same way. For example, when the user puts in "1" the second time, the Input Text box is cleared and the program does not advance to the correct frame. I thought it might be because it's still trapped in the if/else routine, but maybe it's something else. I'm stumped, which is not surprising given my level of expertise here.

                 

                Thanks for the help.

                • 5. Re: "Exit" in director is ? in Flash
                  kglad Adobe Community Professional & MVP

                  try:

                   


                   

                      if (gNumber == "1") {
                          gotoAndPlay("input");
                         } else {

                  txt_defNumber.text="";
                          txt_incorrect_number.text = "Please type the number 1."
                      }

                   

                   

                  • 6. Re: "Exit" in director is ? in Flash
                    Chemistry guy Level 1

                    many thanks...it now works


                    • 7. Re: "Exit" in director is ? in Flash
                      kglad Adobe Community Professional & MVP

                      you're welcome.