3 Replies Latest reply on Sep 13, 2011 11:44 PM by Designscripting

    SetInterval and Standard Deviation

    riceroman3

      I’m sure this question is too complicated for an immediate answer so I’m looking for suggestions on where to find reference material or general guidance.

       

      I’m trying to combine the setInterval function and Math.Random within a specified range (say 1 - 5 seconds) so I can time the length of movie clips in a binomial distribution (68% of the occurrences fall within one standard deviation).

       

       

      Any suggestions?

       

      Thanks,

       

      Mike

       

       

       

        • 1. Re: SetInterval and Standard Deviation
          clbeech Level 3

          although I don't quite understand what you're trying to acheive exactly, here is a basic methodology to create a method that is called, reassigning setInterval using a random timeframe.

           

          this system will require the passing of a method that you can then use to execute whatever operation you would prefer at the end of the delay - one could also pass a 'time' to a method to statically 'set' the delay time - also included below.

           

          var timer:Number;
          var initMethod:Function;
          
          function rndDelay(method:Function):Void {
            var delay = 1000 + Math.random() * 4000; //1-5 seconds
            initMethod = method;
            timer = setInterval(initDelayMethod, delay);
          }
          
          function setDelay(time:Number, method:Function):Void {
            initMethod = method;
            timer = setInterval(initDelayMethod, time);
          }
          
          function initDelayMethod():Void {
            clearInterval(timer);
            initMethod();
          }
          
          • 2. Re: SetInterval and Standard Deviation
            kglad Adobe Community Professional & MVP

            there's no reason to time movieclips unless there are performance issues (just check the movieclips _totalframes).  if there are performance issues, an enterframe loop is preferable to setInterval().

            1 person found this helpful
            • 3. Re: SetInterval and Standard Deviation
              Designscripting Level 1

              Easy formula to find standard deviation and variance.

               

              Standard Deviation

               

              Standard Deviation and variance calculator