12 Replies Latest reply on Feb 11, 2009 8:56 AM by Ned Murphy

    variable for counting items clicked

    W_Bell Level 1
      I am not sure about ther variable method I am trying to make.
      It is supposed to keep track of how many buttons are pressed out of 6 buttons.

      My code is:
      //Set the variable
      var onoff =0;

      //press button to add or subtract from the var
      myButton.onPress = function() {
      onoff = 0+1;
      if (onoff=6) {//All on/off memory var
      menuButton_All_On._visible = false;

      } else {
      menuButton_All_On._visible = true;
      };

      //Problem is I think myButton press is setting the var to 0 each time it adds or subtracts from it.
        • 1. variable for counting items clicked
          Ned Murphy Adobe Community Professional & MVP
          It probably equals 1 after each click since you assign it to be so. Try:

          onoff += 1;

          I don't see where anything is subtracting though.
          • 2. Re: variable for counting items clicked
            W_Bell Level 1
            I guess te code should be more complete.
            Here it is with your syntax.
            Is this what you mean?

            //Set the variable
            var onoff =0;

            //press button to "add" to the var
            myButton.onPress = function() {
            onoff +=1;
            if (onoff=6) {//All on/off memory var
            menuButton_All_On._visible = false;

            } else {
            menuButton_All_On._visible = true;
            };

            //press button to "subtrat" to the var
            myButton_2.onPress = function() {
            onoff -=1;
            if (onoff=6) {//All on/off memory var
            menuButton_All_On._visible = false;

            } else {
            menuButton_All_On._visible = true;
            };


            //This seems to be a lot of code to do the 2 functions...
            can anyone suggest a more streamlined way?

            Thank you NedWebs
            • 3. Re: variable for counting items clicked
              rlc5611 Level 1
              use == with if
              • 4. Re: variable for counting items clicked
                Ned Murphy Adobe Community Professional & MVP
                Your code is not going to give you the result first described... "It is supposed to keep track of how many buttons are pressed out of 6 buttons." So you may have to re-explain the true goal of this code, along with what's going on with the "menuButton_All_On._visible" element.

                And as ric mentions, use == for comparisons
                • 5. variable for counting items clicked
                  W_Bell Level 1
                  That was a poor start for this thread, sorry.
                  Here is more comprehensive code that I think may work more efficiently.

                  The problem may be that the "var" can go past 6 or less than 0
                  I think this won't apply though it there can only be 6 buttons that can execute the + and 6 for the -.

                  Please see attached code:
                  • 6. Re: variable for counting items clicked
                    Ned Murphy Adobe Community Professional & MVP
                    My questions still stand. What are you really trying to accomplish, and what goes on with that MenuButton_All_On element.

                    Even if there are 6 buttons, you could press the same Up button 6 times and the show is over (?), so it's not clear what the scenario involves,
                    • 7. variable for counting items clicked
                      W_Bell Level 1
                      the 6 up buttons turn themselves ._visible = false so they won't be seen once clicked. So there can only be 6 clicks total.

                      When these upButtons are clicked the down state button appears from underneath them. These down state buttons then executes the - code and turn on the up buttons. So again there can only be 6 clicks one way or another.

                      The "MenuButton_All_On" is a master button to turn all stuff {including the button states) on or off.
                      That is why I needed some way to show this button off after all the single items are off or on.
                      It is not to important if only 4 or 5 is selected because it would still turn the reast on or off.

                      The problem I see now here is that, when the buttons are all off and the user clicks on of the down state
                      buttons, it turns the "MenuButton_All_On" back on only after one click. This has to happen now after 6 "-" clicks.
                      • 8. Re: variable for counting items clicked
                        Ned Murphy Adobe Community Professional & MVP
                        So you can click the same Up button 6 times and get them all to disappear? Is that what you want?
                        • 9. variable for counting items clicked
                          W_Bell Level 1
                          Yes,
                          The problem I see now here is that, when the buttons are all off and the user clicks on the down state buttons, it turns the "MenuButton_All_On" back on only after one click. This has to happen now again only after 6 "-" clicks.
                          • 10. Re: variable for counting items clicked
                            Ned Murphy Adobe Community Professional & MVP
                            You need to have some stored info regarding the clicks and who's currently playing. You could have a boolean variable, call it upMode or something and set it to true when the Up buttons are active. When you reach that 6 count, switch that variable value to false until the Down folks do their job.

                            Or, you could try just adding a second conditional instead of the "else" by itself, have it...

                            else if(onoff == 0){

                            That may take care of the counting down side of things. It should work if you are only counting up to start with
                            • 11. Re: variable for counting items clicked
                              W_Bell Level 1
                              This code will address the task.
                              Thank you NedWebs

                              • 12. Re: variable for counting items clicked
                                Ned Murphy Adobe Community Professional & MVP
                                You're welcome