4 Replies Latest reply on Apr 24, 2009 11:34 AM by brian914

    a number between....

    brian914 Level 1

      I want to test if a number is between a low and high number. In my case if it is between 1 and 3. I thought I could do it like this, but seems like this does not work.

       

       

      if(currentSubBtn >= 1 && currentSubBtn <= 3)

      {

       

      }

       

       

      If not && what do I have to use?

       

      Thank you!

        • 1. Re: a number between....
          kglad Adobe Community Professional & MVP

          that syntax is correct.  it's just questionable whether currentSubBtn is a numeric variable.

          • 2. Re: a number between....
            robdillon Most Valuable Participant

            If works for me. I tried this:

             

            var currentSubBtn:Number = 2;

             

            if (currentSubBtn>=1 && currentSubBtn<=3) {
                trace("yes");
            } else {
                trace("no");
            }

             

            How are you defining the value of currentSubBtn?

            • 3. Re: a number between....
              Rothrock Level 5

              My guess is that currentSubBtn is a value which is changing over time and that you are only testing the conditional once, at a time when currentSubBtn isn't in that range. If that is a case then you will need to put the conditional inside an onEnterFrame handler or something like that to keep testing over and over until your condition is met.

               

              You could also add a couple things to your code to help you see what is going on.

               

              On the line before the conditional add a trace statement:

               

              trace("The current value of currentSubBtn is: "+currentSubBtn);

               

              You can also do as Rob Dillon has shown add an else statement to your conditional. That way you know you are reaching the conditional and how it is evaluating.

              • 4. Re: a number between....
                brian914 Level 1

                It is a number. Not sure why that is not working, I just build a work around that might not be as pretty, but will have to do for now.

                 

                Thank you so much for the help!!!

                 

                Here is what I have now, that works. This is triggered through a keyboard click event, so the forward and back arrows change the pages in my file.

                 

                function getKeyPressed():Void{

                     trace("key was pressed");

                    

                     //Back button action

                     if(Key.getCode() == 37)

                     {

                          if(currentSubBtn >= 1)

                          {

                               backPage();

                          }

                     }

                    

                     //Next button action

                     else if(Key.getCode() == 39)

                     {

                          if(currentSubBtn <= 3)

                          {

                               nextPage();

                          }

                     }

                }