7 Replies Latest reply on Feb 10, 2009 8:18 AM by GumpsterF

    if - else statements

    GumpsterF Level 1
      Can some one tell me why my if- else statement is not returning a value?
        • 1. Re: if - else statements
          GumpsterF Level 1
          Why doesn't my "if - Else" code under the "add_up.onRelease = function()"
          Return values for my afterDP number?
          • 2. Re: if - else statements
            GumpsterF Level 1
            I tried this too...
            • 3. Re: if - else statements
              robdillon Most Valuable Participant
              I didn't recreate your movie, but looking at the code in the first example, I see one problem immediately. You have a set of variables defined like this:
              var myCheckbox_11:Number;
              myCheckbox_11 = 0;
              var myCheckbox_12:Number;
              myCheckbox_12 = 0;
              var myCheckbox_13:Number;
              myCheckbox_13 = 0;

              Then further on, it looks like you have three checkbox component instances with the same names as the variables above. With duplicate names, in actionscript whichever is referenced first wins, the rest are ignored. Either rename the variables or rename the checkboxes. There may be more problems other than this.
              • 4. Re: if - else statements
                GumpsterF Level 1
                Hi again Rob. Actually those variables were working lol
                I have greatly simplified the document and code down to what I would like to work. All I want to know is why I cannot get to my else statement even I have satisfied the argument! This is driving me crazy......
                • 5. Re: if - else statements
                  Ned Murphy Adobe Community Professional & MVP
                  It's a little confused because in both conditionals you appear to be looking for a number, != NaN means it will pass if it is a number, though you have it say it isn't.
                  • 6. Re: if - else statements
                    robdillon Most Valuable Participant
                    You can fix this in a couple of ways. You don't want to equate the value of afterDP to NaN. Number(tradeIn.text) will equate to NaN if nothing is entered, but that doesn't mean that using that value is a good idea for a test.

                    You could use this:
                    var startNum:Number = 12000;
                    trace(startNum);

                    finalPrice.text = "";
                    tradeIn.text = "";
                    tradeIn.restrict = "0-9";

                    add_up.onRelease = function() {
                    var afterDP = startNum-Number(tradeIn.text);

                    if (tradeIn.text == "") {
                    finalPrice.text = startNum;
                    trace("not a number");
                    } else {
                    finalPrice.text = afterDP;
                    trace("is a number");
                    }
                    };

                    or, you could use the far simpler:
                    var startNum:Number = 12000;
                    trace(startNum);

                    finalPrice.text = "";
                    tradeIn.text = "0";
                    tradeIn.restrict = "0-9";

                    add_up.onRelease = function() {
                    var afterDP = startNum-Number(tradeIn.text);
                    finalPrice.text = afterDP;
                    };

                    If you give tradeIn.text an initial value, you don't have to test at all.
                    • 7. Re: if - else statements
                      GumpsterF Level 1
                      Thanks Rob. I understand now. Thanks so much, that was driving me crazy.

                      And sorry Ned, I am sure that looked confusing, I should have phrased my question more clearly. I was looking for a way to calculate my final price if there was nothing entered in the "tradeIn.text" field.

                      Thanks to you both!

                      Forrest