4 Replies Latest reply on Apr 4, 2007 4:30 AM by phil ashby

    Tracking how many times a button is clicked by user

    rchdesigns
      I am building a website the I need to know how many times a button is pressed and how many times a movie is loaded. I'm in the process of trying to make a hit counter activated bya button click but am having no luck.

      I have searched all over the web and have found nothing. I'm sure that someone has tried this before.
      Any suggestions would be greatly appreciated, or just point me inthe right direction.

      Thank you
      Kevin
        • 1. Re: Tracking how many times a button is clicked by user
          ckpepper02
          What type of button are you using? if you're using the button component, you will need to set up a listener:
          You should declare a variable, probably on your main timeline.
          var hitCount = 0;

          btnListener = new Object();
          btnListener.click = function () {
          hitCount++;
          }
          instanceOfButton.addEventListener("click", btnListener);

          Or, if its a regular button symbol, you can just use the on (press) event.
          on (press,release,whatever) {
          hitCount++;
          }
          then in the main timeline, you can use an if statement for whenever the hitCount variable reaches a certain number...

          if (hitCount == 7){
          trace("you've clicked 7 times");
          }

          Hope this helps you. If not, let me know, I'll keep tryin
          • 2. Re: Tracking how many times a button is clicked by user
            rchdesigns Level 1
            Thanks for replying
            I am using a regular button symbol.
            Is there a way to export the count to .php so I can have my client login to that page and review results?

            • 3. Re: Tracking how many times a button is clicked by user
              richieboy1
              u can get the count as ckpepper02 mentioned but send the dat by doing the following
              AS code
              var senddata:LoadVars=new LoadVars();
              var receivedata:LoadVars=new LoadVars();
              senddata.hit=hitcount; //"hitcount" is ur variable that stores the count,"hit" is the variable to access on server side
              senddata.sendAndLoad("myphp.php",receivedata,"POST");
              //optional
              receivedata.onLoad=function():Void{
              continue;
              }

              on the php side get the value as
              $hitcnt=$_POST['hit'];
              hope this helps
              • 4. Re: Tracking how many times a button is clicked by user
                phil ashby Level 1
                except that that will only keep a running check of the hits for a single viewing of the movie. If you want to keep track of all the hits for all users, you'll need to have a hitcount stored in a database or similiar and update it by one upon each hit.