6 Replies Latest reply: Mar 12, 2012 2:33 PM by teacheRuss RSS

    Input Text will not allow me to access the correct answer!

    teacheRuss Community Member

      Hi All

       

      • i am trying to create a simple quiz in school. I have one test question which requires the answer to be -1.
      • I have created Input text and assigned the variable answer for this question.
      • I have a button with the following AS2 script:

       

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

          if(answer eq "-1" or answer eq "minus 1"

             or answer eq "Minus 1" or answer eq "Minus one" or answer eq "minus one")

       

          {_root.gotoAndStop(2)

       

          } else

       

          {_root.gotoAndStop(3)

          }

      }

       

      • Firstly whatever you type the numerical keys are immobilised on the keyboard when the .SWF file is built
      • Secondly I cannot enter the correct answer!! If I type in Minus 1 etc it goes to frame 3.
      • I have tried flags rather than frame numbers - same problem.
      • i have tried remaking the quiz as a  separate file.
      • using CS4 and CS5 flash - windows 7 PC.

      Please help!!

      teacheRuss

        • 1. Re: Input Text will not allow me to access the correct answer!
          Ned Murphy CommunityMVP

          You should try tracing the value of answer in that function to see why it is not working, as in trace(answer);

           

          Instead of assigning a variable to the textfield, just should assign an instance name to the textfield and read the text property of the textfield.

           

          You should also avoid placing code "on" objects and keep your code in the timeline... again, this involves assigning an instance name to the button and targeting it using that name.  In the code below, which goes into the timeline, the textfield is named "Answer" and the button is named "yourBtnName"

           

           

          yourBtnName.onRelease = function() {

              if(answer.text == "-1" || answer.text == "minus 1" || answer.text == "Minus 1" || answer.text == "Minus one" || answer.text == "minus one") {

                   _root.gotoAndStop(2)

               } else  {

                   _root.gotoAndStop(3)

               }

          }

          • 2. Re: Input Text will not allow me to access the correct answer!
            teacheRuss Community Member

            Ned

             

            Thanks for the reply. I had instances for all elements but had code on teh but (Instance Enter). I have tried your code with my instance names. The button is Q1 (I was going to add more if it worked). The vaiable name for the Insert text box is ans1 so I used the code below. I added the code to frame 1 in teh timeline. I think this is what you meant so a frame script as opposed to a buton script. i have always scriped buttons (very simple). I have played around with the trace(); function but i am not sure where to run it from. I have added it to the script below. I tried Q1 which is the button and ans1 (variable). It must be wrong as I cannot see any output. Last thing. Is it not right ot use eq and or?? I am using Actionscript 2.

            The disabled keys is the same running the code on my mac and pc!

             

            Q1.onRelease = function() {

             

                if(ans1.text == "-1" || ans1.text == "minus 1" || ans1.text == "Minus 1" || ans1.text == "Minus one" || ans1.text == "minus one") {

             

                     _root.gotoAndStop(2)

             

                 } else  {

             

                     _root.gotoAndStop(3)

             

            trace(Q1);

             

                 }

             

            }

            • 3. Re: Input Text will not allow me to access the correct answer!
              Ned Murphy CommunityMVP

              Do not assign ans1 as the variable.  Assign it as the instance name, just like you hopefully did for the button (and get rid of it as the variable). Instance names are assigned to objects on the stage using the Properties panel where it says <Instance Name>

               

              If you want to see what the ans1 text is, then the first thing you need to do is trace that, not Q1.  The second thing is that you should trace it outside of the conditional... otherwise you will only see it under one condtion...

               

              Q1.onRelease = function() {

                 

                  trace(ans1.text);

               

                  if(ans1.text == "-1" || ans1.text == "minus 1" || ans1.text == "Minus 1" || ans1.text == "Minus one" || ans1.text == "minus one") {

               

                       _root.gotoAndStop(2)

               

                   } else  {

               

                       _root.gotoAndStop(3)

               

                   }

               

              }

              • 4. Re: Input Text will not allow me to access the correct answer!
                teacheRuss Community Member

                Ned

                 

                I understand it now. I didn’t give the variable a name at all. Oddly I have always been told to assign variable names!! I tried this back in school on a new composition. No crashes. Oddly I have CS5 on my Mac and PC at home and again some of the keys are disabled on both machines from the same file. At school we are running CS4.

                 

                Is there anything that we need to do as we will be upgrading to CS5 or 5.5 in our summer term?

                 

                Thanks again

                 

                Russell

                • 5. Re: Input Text will not allow me to access the correct answer!
                  Ned Murphy CommunityMVP

                  Oddly, that is a problem that prevails in alot of schools... people are taught poor practices... using variables for textfields is one of them, and putting code "on" objects is another.  I can only guess it's because the instructors learn bad practices and don't expand their abilities beyond what they learn/teach.

                   

                  As far as keys failing goes, I am guessing that you are trying to test/run a file in the Flash IDE that implements keyboard controls and have not disabled the keyboard shortcuts.  What happens is while you play the file, some keys retain their shortcut processing so they do not function as desired. What you need to do in this case is set the player to disable the shortcuts, which is done via the player's toolbar options (Control -> Disable Keyboard Shortcuts).  You only need to do it once for an editing session, the player will retain that setting each time you run the file afterwards during a session.  If you run the file outside of Flash you should not have this problem at all... it only occurs while using the player in the editor.

                  • 6. Re: Input Text will not allow me to access the correct answer!
                    teacheRuss Community Member

                    Ned

                     

                    I only seem to have the keyboard problem in Flash CS5. I have disabled Keyboard shortcuts, closed and opened the file in Flash Player without the Flash editor even open - the problem remains. The keys I can use are as follows:  aceghinoQrstWy134.  Oddly Q and W come up as capitals when the file is running. All other numbers and letters are disabled.

                     

                    Anything else I can try?

                     

                    Russell