5 Replies Latest reply on Jun 13, 2008 2:29 PM by FlashTastic

    IF Statement

    Mr.Wallace Level 1
      Hey all,

      I'm sure this has been asked in these forums somewhere else but the searches aren't coming up with answers for me so please forgive me if I'm repeating a question...

      I'm trying to create a section of a project where users have to enter text into 4 different 'input text boxes' and hit the 'enter' key (or '13', ENTER key code) in order to move on to the next section of the project. The text in the boxes can only be answered with the correct answers (either upper or lower case preferrably) before advancing on. For example:

      Box1 = ANSWER1 //or 'answer1'
      Box2 = ANSWER2 //or 'answer2'
      Box3 = ANSWER3 //or 'answer3'
      Box4 = ANSWER4 //or 'answer4'

      I have figured out how to code it to accept the crrect answer(s) if there is only one 'input text box' but when it comes to multiple boxes...I'm lost. I must be having a brain fart or something cause I know it's an easy fix but I can't figure it out for some reason. I've tried multiple IF statements but if even one of the statements are correct it will advance. I need ALL fields to be correct.

      I'm using MX Pro 2004 (AS 2).

      Any ideas???
        • 1. Re: IF Statement
          FlashTastic Level 1
          if(Box1.text.toLowerCase() == "answer1" && Box2.text.toLowerCase == "answer2" && Box3.text.toLowerCase() == "answer3" && Box4.text.toLowerCase == "answer4){
          //correct
          }else{
          //incorrect
          }

          Cheers,
          FlashTastic
          • 2. Re: IF Statement
            Mr.Wallace Level 1
            You know what FlashTastic, I think you have through for me a few times now and I am really , really grateful for your help!

            I was so close to what you had, LOL! Everything is working great right now...well, except the uppercase and lowercase letters part, but that's cool. I just have to make a note to the users to enter the text in uppercase letters only (I'd prefer uppercase to lowercase if I have to choose between them).

            THANK YOU soooo much!
            • 3. Re: IF Statement
              Mr.Wallace Level 1
              I have an addition an issue that has come up now, the 'else' statement is being goofy.

              When I put it into the coding and publish it, it doesn't let me enter in the entire right word before it jumps tothe "incorrect" page. This is the code:

              Selection.setFocus(Box1);

              keylistener = new Object();
              keylistener.onKeyUp = function() {

              if (Box1.text == "Answer1" && Box2.text == "Answer2" && Box3.text == "Answer3" && Box4.text == "Answer4" && Box5.text == "Answer5" && Key.getCode() == 13) {
              Key.removeListener(keylistener);
              gotoAndStop("correct");
              }
              if (name.text !== "Answer1") {
              gotoAndStop("incorrect");
              }
              };
              Key.addListener(keylistener);

              I'm sure it has something to do with the 'keyUp' part. As soon as I try to enter 'Answer1', it goes to 'incorrect' because its reading the answer as soon as I lift my finger off of the 'A' button.
              • 4. Re: IF Statement
                Mr.Wallace Level 1
                I have an addition an issue that has come up now, the 'else' statement is being goofy.

                When I put it into the coding and publish it, it doesn't let me enter in the entire right word before it jumps tothe "incorrect" page. This is the code:

                Selection.setFocus(Box1);

                keylistener = new Object();
                keylistener.onKeyUp = function() {

                if (Box1.text == "Answer1" && Box2.text == "Answer2" && Box3.text == "Answer3" && Box4.text == "Answer4" && Box5.text == "Answer5" && Key.getCode() == 13) {
                Key.removeListener(keylistener);
                gotoAndStop("correct");
                }
                if (name.text !== "Answer1") {
                gotoAndStop("incorrect");
                }
                };
                Key.addListener(keylistener);

                I'm sure it has something to do with the 'keyUp' part. As soon as I try to enter 'Answer1', it goes to 'incorrect' because its reading the answer as soon as I lift my finger off of the 'A' button.
                • 5. Re: IF Statement
                  FlashTastic Level 1
                  The problem is that you're checking for the right answer every time a key is released.

                  There's a few approaches you can take here.

                  1. You could give a clue to your users how many letters is in the answer and then modify your code as follows:

                  var numberOfLetters = 5;
                  if (name.text !== "Answer1" && name.text.length >= numberOfLetters) {
                  gotoAndStop("incorrect");
                  }

                  2. You build in a "check answers" button, which only does the comparison after the button is pressed.

                  3. Instead of redirecting the movie to an "incorrect" frame, simply color the text red if the answer is wrong, or color the text green if the answer is right.

                  That's all I can think of for now, but there's many different solutions.

                  Cheers,
                  FlashTastic