Skip navigation
teacheRuss
Currently Being Moderated

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

Mar 8, 2012 9:59 AM

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

 
Replies
  • Currently Being Moderated
    Mar 8, 2012 11:57 AM   in reply to teacheRuss

    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)

         }

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 8, 2012 3:10 PM   in reply to teacheRuss

    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)

     

         }

     

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 9, 2012 5:20 AM   in reply to teacheRuss

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points