1 Reply Latest reply on May 31, 2010 8:17 AM by kglad

    Problem in making a simple program. Please Help

    David C18

      Hi i am currently working on a simple program that when the user clicks a button it adds 1 to a text box for whatever button has been pressed. For example they click a heads button it puts 1 into the box, they click 1 in the tails button and it displays another 1 in the the box.

       

      What i am having a problem with is that once the total number of clicks has been done (15) i want it to stop and not allow anymore clicks.

       

      Here is my code so far:

       

      btn_Heads.addEventListener(MouseEvent.CLICK, runHeads);
      btn_Tails.addEventListener(MouseEvent.CLICK, runTails);
      btn_Clear.addEventListener(MouseEvent.CLICK, clearData);

       

      var coinArray:Array = new Array();
      var headsTotal:int=0;
      var tailsTotal:int=0;
      var counter:int=0;

       

      //Code for the counter on the heads button. //
      //Adds 1 onto the counter each time it is clicked//

       

      function runHeads (evt) {
          coinArray[counter]
              headsTotal=headsTotal+1;
                  counter++;
                      txt_Heads.text=String(headsTotal);
                      txt_Total.text=String(counter);

       


      }
      function runTails (evt){
          coinArray[counter]
              tailsTotal=tailsTotal+1;
                  counter++;
                      txt_Tails.text=String(tailsTotal);
                      txt_Total.text=String(counter);               
      }

       


      function clearData (evt){
          txt_Total.text = "";
          txt_Heads.text = "";
          txt_Tails.text = "";
          txt_PerHead.text = "";
          txt_PerTails.text = "";
          coinArray = new Array();
          headsTotal = null;
          tailsTotal = null;
          counter = 0;
      }

       

      The code runs all and well but when the total value reaches 15 i want it to stop and not allow anymore clicks.I was trying a for loop but i wasn't sure if what i was doing was right

       

      Basically all i need it to do is that the Box's that are getting numbers put in them i need the total 1 to stop at 15 and not allow anymore changes.

       

      If anyone can please help it would be much appreciated.

        • 1. Re: Problem in making a simple program. Please Help
          kglad Adobe Community Professional & MVP

          use:

           


           

          btn_Heads.addEventListener(MouseEvent.CLICK, runHeads);
          btn_Tails.addEventListener(MouseEvent.CLICK, runTails);
          btn_Clear.addEventListener(MouseEvent.CLICK, clearData);

           

          var coinArray:Array = new Array();
          var headsTotal:int=0;
          var tailsTotal:int=0;
          var counter:int=0;

           

          //Code for the counter on the heads button. //
          //Adds 1 onto the counter each time it is clicked//

           

          function runHeads (evt) {
              coinArray[counter]
                  headsTotal=headsTotal+1;
                      counter++;

          checkCounterF();
                          txt_Heads.text=String(headsTotal);
                          txt_Total.text=String(counter);

           


          }
          function runTails (evt){
              coinArray[counter]
                  tailsTotal=tailsTotal+1;
                      counter++;

          checkCounterF();
                          txt_Tails.text=String(tailsTotal);
                          txt_Total.text=String(counter);               
          }

           

          function checkCounterF(){

           

          if(counter>=15){

           

          btn_Heads.removeEventListener(MouseEvent.CLICK, runHeads);
          btn_Tails.removeEventListener(MouseEvent.CLICK, runTails);
          //you might want to check if the listeners need to be re-added in clearData

          }

           

          }


          function clearData (evt){
              txt_Total.text = "";
              txt_Heads.text = "";
              txt_Tails.text = "";
              txt_PerHead.text = "";
              txt_PerTails.text = "";
              coinArray = new Array();
              headsTotal = null;
              tailsTotal = null;
              counter = 0;
          }