12 Replies Latest reply on Oct 10, 2009 4:56 AM by Ned Murphy

    AS2_Input Box Problem

    Feed_Me_Info_Plz Level 1

      I am writing a small spelling wordgame program for a child and am battling a bit. I am new to this and still have alot to learn.

       

      a Code found on webwasp using instance name:

       

      on (press) {

            if (textbox.text.indexOf("car") != -1) {

              gotoAndStop("right");

            } else {

              gotoAndStop("wrong");

            }

         }

       

       

      a Second code also tried also found on webwasp using var:

       

      on (release, keyPress "<Enter>") {

      if (answer eq "rooster" or answer eq "cockerel") {

      gotoAndPlay ("right");

      } else if (answer eq "hen" or answer eq "chicken") {

      gotoAndStop ("clue");

      } else {

      gotoAndStop ("wrong");

      }

      }

       

      I have tried both ways and no luck. No matter what is entered it only goes to the wrong label even if correct answer entered.

      I have embedded to lowercase.

      Can someone please help. I am stuck.

        • 1. Re: AS2_Input Box Problem
          Ned Murphy Adobe Community Professional & MVP

          Both sets of code should work if you have the rest of the design in place to support it.  You'll need to describe what objects you have created and what you have done to prepare them.

           

          The first approach is the better one, but only in terms of using the text property of the textfield to get the value that is enetered in it.  Using the variable approach as the second one does is sometimes tricky and better avoided.  You could still use the second approach as a basis, I would just switch it to using the text property like the first.

          1 person found this helpful
          • 2. Re: AS2_Input Box Problem
            Ned Murphy Adobe Community Professional & MVP

            I created a small sample file for you to look at.  I took a slightly different approach using the first bit of code you offered.  The difference being that I gave the button an instance name (btn) and I used that to target the code to the button from the timeline rather than placing the code on the button as your approach would be doing.  Having the code on the timeline is a better practice as it makes it easy to find and better organized.  Here's a link, it is a Flash 8 file...

             

            http://www.nedwebs.com/Flash/AS2_Input_Text.fla

            1 person found this helpful
            • 3. Re: AS2_Input Box Problem
              Feed_Me_Info_Plz Level 1

              Thanks Ned. I tried opening your file but it gave me a unexpected file type error.

               

              I have attached the 2 versions of what I am trying to do.

              • 4. Re: AS2_Input Box Problem
                Feed_Me_Info_Plz Level 1

                Thanks Ned. I tried your file but it gives me an unexpected file type error.

                 

                I have attached the two versions of what I'm trying to do.

                • 5. Re: AS2_Input Box Problem
                  Feed_Me_Info_Plz Level 1

                  Thanks Ned. I tried your file but it gives me an unexpected file type error.

                   

                  I am trying to attach the file but it says unauthorised.

                  • 6. Re: AS2_Input Box Problem
                    Ned Murphy Adobe Community Professional & MVP

                    Chances are you are using an earlier version of Flash than the Flash 8 file I linked.  You aren't having much luck attaching any files... you can't attach files with an fla extension.  In any case, if you can respond to my first reply and explain what you've assembled, it may be possible to see what you missed.

                    • 7. Re: AS2_Input Box Problem
                      Feed_Me_Info_Plz Level 1

                      I am using Flash CS4 with my publishing settings set to Flash10 and AS2.

                       

                      in short:

                       

                      I made a input box and gave it an instance name of: textbox, with the following atributes:

                       

                      size 36, font Comic Sans, left alignment, line type: Single Line, text is selectable and show border around selected.

                       

                      max charachters 12, var left blank

                       

                      embedded to lowercase only

                       

                      I then used a button from the common library with the following code attached.

                       

                      on (release, keyPress "<Enter>") {

                      if (textbox.text.indexOf("car") != -1) {

                      gotoAndStop ("right");

                      }else {

                      gotoAndStop ("wrong");

                      }

                      }

                       

                      everything compiles with no error and runs but even if entering car it still goes to the else command.

                       

                       

                       

                       

                       

                      • 8. Re: AS2_Input Box Problem
                        Ned Murphy Adobe Community Professional & MVP

                        In the version I made I created an input textfield and assigned it an instance name of textbox.  I created a button symbol and assigned it an instance name of btn.  I extended the timeline to include two more keyframes with the labels of right and wrong.  I placed the following code in the timeline...

                         

                        stop();

                        btn.onRelease = function() {
                              if (textbox.text.indexOf("car") != -1) {
                                gotoAndStop("right");
                              } else {
                                gotoAndStop("wrong");
                              }
                        }

                         

                        For the sake of apples to apples, I just placed a copy of the button symbol on the stage and attached the following code to it...

                         

                        on(release, keyPress "<Enter>") {
                              if (textbox.text.indexOf("car") != -1) {
                                gotoAndStop("right");
                              } else {
                                gotoAndStop("wrong");
                              }
                        }

                         

                        All three options, the two buttons and the Enter key produce the correct results.  I have updated the file I made available earlier for the above and also saved it as a CS3 file this time around.  See if you can get the revised version to open.

                        • 9. Re: AS2_Input Box Problem
                          Feed_Me_Info_Plz Level 1

                          Hi Ned,

                           

                          Thanks for your assistance. I created an instance name for the button and placed the code on the timeline as per your sample.

                           

                          IT WORKS!!! Great.

                           

                          I tried the second code as per your sample which seems exactly similar to mine and still doesn't work. I saw in your sample that your labels are 5 frames long, mine is only 1 frame could that be a reason wor it not work in this code?

                           

                          And is there a way to use the keyPress("Enter") with the btn instance code on the timeline?

                           

                          Once again thanks a million.

                          • 10. Re: AS2_Input Box Problem
                            Ned Murphy Adobe Community Professional & MVP

                            It shouldn't matter that I spread things out on the timeline.  Here's some timeline code for keyboard detection

                             

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

                            keyListener.onKeyUp = function(){
                            //trace(Key.getCode());  // use this to find a key code
                            if(Key.getCode() == 13){
                              trace("clicked Enter key");
                            }
                            }

                            • 11. Re: AS2_Input Box Problem
                              Feed_Me_Info_Plz Level 1

                              Thanks Ned,

                               

                              I changed the code to my needs and it works perfectly.

                               

                              Thanks.

                               

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

                              keyListener.onKeyUp = function(){
                              //trace(Key.getCode());  // use this to find a key code
                              if(Key.getCode() == 13){
                                trace("clicked Enter key");
                              if (_root.bug_answer.text.indexOf("bug") != -1) {
                                gotoAndStop("right_bug");
                                    } else {
                                gotoAndStop("wrong_bug");
                                    }

                              }

                              }

                              • 12. Re: AS2_Input Box Problem
                                Ned Murphy Adobe Community Professional & MVP

                                You're welcome