5 Replies Latest reply on Feb 25, 2010 5:26 AM by Ned Murphy

    my if statement


      something is wrong with my if statement. It continues to work and send letters with out verifying the reqirement first. HOw can I fix this?


      on (release) {
      if (EMail.indexOf("@") != -1 && EMail.indexOf(".") != -1) {
        if (Name eq "") {
         _parent.Status = "Please enter your name";
        } else if (Email eq "") {
         _parent.Status = "Please enter email Address";

        } else if (Website eq "") {
         _parent.Status = "Please enter the URL to your website";
        } else {
         Submit = "Yes";
         NumHigh = 10;
         NumLow = 0;
         _parent.GuestBook = "Processing..   Loading New... ";
         loadVariables ("GuestBook.php", 0, "POST");
         _parent.Status = "Your entry has been submitted.  You should see your comments appear immediatly";
      } else {
        _parent.Status = "Please enter a valid email Address";

        • 1. Re: my if statement
          Ned Murphy Adobe Community Professional & MVP

          You'll need to explain what is involved in the code you show and how your design relates to it.  What and where are the variables you are testing?  Have you tried tracing them to see why they might pass the tests?


          When it comes to testing for empty entries, I normally test the string's length rather than the string value.  It helps avoid blank spaces as entries.  In some cases you would know there has to be some minimum length as well.  You don't need that particular inner Email test if the outer one is already confirming it has those characters.

          • 2. Re: my if statement
            Harry Kunz Level 4

            The conditional statement if(EMail.indexOf("@") != -1 && EMail.indexOf(".") != -1) is correct. The only flaw is that when EMail is undefined, the condition will become true and execute its code. Check by tracing the value of EMail. It must have returned undefined that's why any methods invoked on it like EMail.indexOf will all return undefined and thus be true because its not equal to -1.

            • 3. Re: my if statement
              samuels2921 Level 1

              I see, it returns undefined, even if I enter something in the text boxes. I think its because i referenced the text boxes with variables instead of instances how can i link this actionscript to a variable instead of instances. Because the form wont work if i set both variables and instances on the text boxes.

              • 4. Re: my if statement
                Harry Kunz Level 4

                Use the instance name instead of the variable. The variable field returns something like:


                <p align="left"><font face="Franklin Gothic Medium" size="100" color="#6666ff" letterSpacing="0.000000" kerning="1">Your text is here</font></p>


                You don't want that. So use the instance name instead. Then in order to use the methods on the instance, do it like this: EMail.text.indexOf("somthing")

                • 5. Re: my if statement
                  Ned Murphy Adobe Community Professional & MVP

                  The var option for textefields is best avoided... either a bad idea to begin with or just poorly implemented by whoever added the capability. Use the TextField.text property to address whatever text is in the string.  If the entry happens to be a number value you can cast it as a nukmber using... Number(tfield.text)