4 Replies Latest reply on Nov 20, 2013 2:22 AM by expjektor

    setInterval in compositionReady

    expjektor

      hi everybody,

       

      i hope someone can help me with my problem:

       

      i want to use setInterval to repeat a function defined in compositionReady but it doesn't work:

       

      var count = 0.;

      var counter_pos = setInterval(countClicks, 200.);

       

      sym.countClicks = function()

      {

      count = count + 1;

      if (count > 10.)

      count = 1.;

      sym.$("dymtext").html(count);

      }

       

      button code: sym.getComposition().getStage().countClicks();

       

       

      but:

      the setInterval works fine by using the click command of the button:

       

      var count = 0.;

      var counter_pos = setInterval(countClicks, 200.);

       

      function countClicks()

      {

      count = count + 1;

      if (count > 10.)

      count = 1.;

      sym.$("dymtext2").html(count);

      }

       

       

      what's wrong with my setInterval in compositionReady?

       

      thanks for your help!

        • 1. Re: setInterval in compositionReady
          michaelAkl Level 1

          that's because in the second option you're using "countClicks" as a global variable so it's defined and recognizable everywhere but in the first option you're defining the function as exclusive to the symbol using the "sym.countClicks",
          so in the first code option , either remove the "sym" from "sym.countClicks = function()" or add "sym" when you call the function , so it would "setInterval(sym.countClicks, 200.);"
          Cheers!

          • 2. Re: setInterval in compositionReady
            expjektor Level 1

            thanks for you answer michael, but i don't get it, it does not work

             

            i put this in compositionReady:

             

            var count = 0.;

            var counter_pos = setInterval(sym.countClicks, 200.);

             

            sym.countClicks = function()

            {

            count = count + 1;

            if (count > 10.)

            count = 1.;

            sym.$("dymtext").html(count);

            }

             

            and this on a click command on a button (a symbol): sym.countClicks();

             

            now it counts up with every click, but the setInverval does not fire.

             

            cheers!

            • 3. Re: setInterval in compositionReady
              michaelAkl Level 1

              try this:

              var TempInterval = setInterval(function() {

                   
                   sym.countClicks();
                   //clearInterval(TempInterval);

              }, 200);

              1 person found this helpful
              • 4. Re: setInterval in compositionReady
                expjektor Level 1

                hi,

                 

                that works, but only inside the button click function and not in compositionReady. anyway - thank you! i will use it that way now.

                 

                cheers!