15 Replies Latest reply on May 16, 2014 5:57 AM by kglad

    how to check correct answer in input text box

    flashnewbie01

      Hey I have a project for school on colons and semicolons. As part of it I want to make a input text box that the player puts the answer to a question in, then clicks a button that checks the input box, and if its correct goes to a correct screen if wrong it goes to a incorrect screen. Unfortunately I don't know how to do this could someone help me. Thanks!

        • 1. Re: how to check correct answer in input text box
          kglad Adobe Community Professional & MVP

          var answerA:Array=['correct answer to question 1', 'answer 2', 'answer 3', ...];

          var questionA:Array=['question 1', 'q2','q3',...];

          var currentQuestion:int=0;

           

          checkAnswer.addEventListener(MouseEvent.CLICK,checkF);

           

          function checkF(e:MouseEvent):void{

          if(answer_tf.text==answerA[currentQuestion]){

          //goto whereever

          }

          }

           

          // somewhere increment currentQuestion

          // check if quiz is completed.

          1 person found this helpful
          • 2. Re: how to check correct answer in input text box
            flashnewbie01 Level 1

            Hey could you clarify. Could you tell me what each line does and what to put in.

            • 3. Re: how to check correct answer in input text box
              kglad Adobe Community Professional & MVP

              aren't you supposed to learn some actionscript in school?

               

               

              // array declarations to setup your project.  arrays are named to make it obvious what they contain and if that's not obvious enough their contents give further hints.

              var answerA:Array=['correct answer to question 1', 'answer 2', 'answer 3', ...];

              var questionA:Array=['question 1', 'q2','q3',...];

              // this keeps track of the current question, starting with 0 (or the first question).

              var currentQuestion:int=0;

               

              // you should have a question textfield and should display the questionA[currentQuestion] in that textfield:

              function displayQuestionF():void{

              question_tf.text=questionA[currentQuestion];

              }

              displayQuestionF();

               

              // checkAnswer is your button the user clicks to check their answer.

              checkAnswer.addEventListener(MouseEvent.CLICK,checkF);

               

              function checkF(e:MouseEvent):void{

              // check if the user's answer (in answer_tf) matches the text in answerA

              if(answer_tf.text==answerA[currentQuestion]){

              //goto whereever

              }

              }

               

              // somewhere increment currentQuestion

              // check if quiz is completed.

              // if not completed, call displayQuestionF() to display the next question.

              1 person found this helpful
              • 4. Re: Re: how to check correct answer in input text box
                flashnewbie01 Level 1

                Ok i tried this and did the following code in a button

                 

                 

                 

                var answerA:Array=['hello', 'Hello', 'Hello.','hello.'];

                var questionA:Array=['question 1'];

                var currentQuestion:int=0;

                 

                function displayQuestionF("What do you say to greet someone?"):void{

                question_tf.text=questionA;

                }

                displayQuestionF("what do you call a grown boy");

                 

                checkAnswer.addEventListener(MouseEvent.CLICK,checkF);

                 

                function checkF(e:MouseEvent):void{

                 

                 

                if(answer_tf.text==answerA[question 1]){

                //goto whereever

                }

                }

                 

                but it still isn't working

                • 5. Re: Re: how to check correct answer in input text box
                  kglad Adobe Community Professional & MVP

                  try:

                   

                  // array declarations to setup your project.  arrays are named to make it obvious what they contain and if that's not obvious enough their contents give further hints.

                  var answerA:Array=['hello1','hello2','hello3','hello4'];

                  var questionA:Array=["what do you call a grown boy1","what do you call a grown boy2","what do you call a grown boy3","what do you call a grown boy4"];

                  // this keeps track of the current question, starting with 0 (or the first question).

                  var currentQuestion:int=0;

                   

                  // you should have a question textfield and should display the questionA[currentQuestion] in that textfield:

                  function displayQuestionF():void{

                  question_tf.text=questionA[currentQuestion];

                  }

                  displayQuestionF();

                   

                  // checkAnswer is your button the user clicks to check their answer.

                  checkAnswer.addEventListener(MouseEvent.CLICK,checkF);

                   

                  function checkF(e:MouseEvent):void{

                  // check if the user's answer (in answer_tf) matches the text in answerA

                  if(answer_tf.text==answerA[currentQuestion]){

                  //goto whereever

                  }

                  }

                   

                  // somewhere increment currentQuestion

                  // check if quiz is completed.

                  // if not completed, call displayQuestionF() to display the next question.

                  1 person found this helpful
                  • 6. Re: Re: how to check correct answer in input text box
                    flashnewbie01 Level 1

                    What type of textfield does the question have to be in? Static, dynamic, or input?

                    • 7. Re: Re: how to check correct answer in input text box
                      kglad Adobe Community Professional & MVP

                      dynamic and your answer textfield should be an input textfield.

                      1 person found this helpful
                      • 8. Re: Re: how to check correct answer in input text box
                        flashnewbie01 Level 1

                        Oh, that explains why it wasn't working.

                        • 9. Re: Re: how to check correct answer in input text box
                          kglad Adobe Community Professional & MVP

                          everything working now?

                          • 10. Re: Re: how to check correct answer in input text box
                            flashnewbie01 Level 1

                            No there is still a bunch of errors. I tried tweaking each but it just caused different errors.

                             

                            Statement must appear within on handler :  var answerA:Array=['hello','Hello','hello.','hello.'];

                            Statement must appear within on handler : var questionA:Array=["What do you call a grown boy1","what do you call a grown boy2","what do you call a grown boy3","what do you call a grown boy4"];

                            The class or interface 'int' could not be loaded. : var currentQuestion:int=0;

                            A type identifier is expected after the ':'. : function displayQuestionF():void{

                            Statement must appear within on handler : displayQuestionF();

                            Statement must appear within on handler : checkAnswer.addEventListener(MouseEvent.CLICK,checkF);

                            The class or interface 'MouseEvent' could not be loaded. : function checkF(e:MouseEvent):void{

                            • 11. Re: Re: how to check correct answer in input text box
                              kglad Adobe Community Professional & MVP

                              are you intentionally using actionscript 2?  if so, why?

                              • 12. Re: Re: how to check correct answer in input text box
                                flashnewbie01 Level 1

                                Yes I'm using Action script 2.0. I'm using it because in action script 3 i can't aply actions to buttons

                                • 13. Re: Re: how to check correct answer in input text box
                                  kglad Adobe Community Professional & MVP

                                  you shouldn't be applying any code to objects even in as2.  further, it's hard to believe anyone would be teaching as2 so you should double check your assignment to see if that is specified (and, if it is, there's a problem with the instruction at your school).

                                  • 14. Re: Re: how to check correct answer in input text box
                                    flashnewbie01 Level 1

                                    Actually Im in an early college program thats called CCTL and Im in the ninth grade. Our class that we are doing this in teaches use the basics of adobe Flash, Indesign, Illustrator, Dreamweaver, Photoshop, and other programs such as Final Cut Pro, Soundtrack Pro, and Juicer. Through all that learning we only learn how to use preset AS2 code so this whole discussion is a trial and error kind of thing. Also i figured out the code to use for AS2 its the following code applied to a button.

                                     

                                    on(release) {

                                      if(input2.text == "I saw Barry walking to the supermarket at 4:30 to purchase some fresh produce; I decided to trip him."){

                                    // input2 is where the player puts the answer and "I saw Barry walking to the supermarket at 4:30 to purchase some fresh produce; I decided to trip him." is the answer

                                      gotoAndPlay("rightreg7");

                                    // rightreg7 is a named frame with the right message

                                      }else{

                                      gotoAndPlay("wrongreg7");

                                    // rightreg7 is a named frame with the right message

                                      }

                                    }

                                    and I figured this out on my own (you gave me AS3 code so your help doesn't count no offense) and when I showed it to my teacher (who worked all his life with these programs) he said he didn't even know you could do that.

                                    • 15. Re: Re: how to check correct answer in input text box
                                      kglad Adobe Community Professional & MVP

                                      your teacher may be an expert in those other adobe programs but he/she is not qualified to teach flash.  and, in any case, your post is in the wrong forum if you want to use as1/as2.

                                       

                                      this is the cc forum and the latest version of flash (cc) doesn't support as1 or as2. your code is as1.