4 Replies Latest reply on Mar 30, 2011 5:11 PM by YueKitsune

    Compare 2 textfields in AS2

    YueKitsune

      I've got a file that sends a random number to another file that uses the number for a password. I have the password sent to a text field that will be hidden from view later, and i type my guess for the password into another text field, then hit the Enter button on the screen. I'm using an on release event for the button, with an if / else statement inside it; Whenever I hit the Enter button it just clears the the text field were i put my guess. If I try and hit the Enter button before I send the number from the other file though it says "correct" like i got the password right. If there's a number in the text field it just clears it out.

       

      function(){return A.apply(null,[this].concat($A(arguments)))}

      on (release) {
      //var myanswer:Number = total.text;
      //var theanswer:Number = feedback.text;
        if (myanswer == feedback.text){
         total.text = "correct";
        } else {
         total.text ="";
        }
      }


      I've tried to make it register that the text fields are numbers but since i just get some variation of the same problem i've phased (i guess that's the term) them out with // for now. feedback.text is were i'm sending the number to, total.text is were my answer goes.

       

      Any help would be great.

        • 1. Re: Compare 2 textfields in AS2
          Ned Murphy Adobe Community Professional & MVP

          Try just comparing the two rtextfields and don't worry about numbers.  If you want to see why things pass or fail, use traces to see what is getting compared.  I don't know how myanswer gets assigned anything the way you just showed it...

           

          on (release) {

            trace(total.text+"   =   "+feedback.text); // what does this report during testing
            if (total.text == feedback.text){
             total.text = "correct";
            } else {
             total.text ="";
            }
          }

          1 person found this helpful
          • 2. Re: Compare 2 textfields in AS2
            YueKitsune Level 1

            before i send the number, and without entering anything into total.text it sends back " = ". if i enter a number in total.text it gives me " ### (whatever number i entered) = "

             

            after i send the number, but before i enter anything it gives me " = whatever number was sent ". and after i type in a number it's" whatever = number sent ".

             

            so it is comparing the numbers, it just isn't recognizing what to do with them, right?

            • 3. Re: Compare 2 textfields in AS2
              Ned Murphy Adobe Community Professional & MVP

              Whatever you are doing is probably what is causing the mixup.   I am not clear as to what you mean when you say "send the number".

               

              The trace is tellling you what is being compared, so any time you have 'something = nothing' or 'nothing = something', you are missing something in how you are managing matters. That should indicate to you what missing pieces you need to manage.

               

              Maybe what you should do is put in another conditional to prevent false entries/testing....

               

              on (release) {

                if(total.length != 0 && feedback.length != 0){ // test only when they both have entries

                   if (total.text == feedback.text){
                      total.text = "correct";
                   } else {
                      total.text ="";
                   }

                }
              }

               

               

               

               

               

              • 4. Re: Compare 2 textfields in AS2
                YueKitsune Level 1

                sorry, i guess i wasn't that clear with the second response. I meant that i was sending the random number to be compared for the password to the file.

                 

                Anyway, i tried what you you suggested and tweaked the code a little bit and that fixed half the problem. Now it won't display "correct" whenver I hit the Enter button, it just clears out the text field with my answer in it. Here's the changes i made.

                function(){return A.apply(null,[this].concat($A(arguments)))}

                on (release) {
                  if(total.length != 0 && feedback.length != 0){
                  //trace(total.text+"   =   "+feedback.text);
                       if (total.text == feedback.text){
                             total.text = "correct";
                       } else if(total.text != feedback.text){
                             total.text ="";
                       }
                }
                }