2 Replies Latest reply on Jul 18, 2007 11:51 AM by kglad

    Slowing the speed of a function

    Jason_Savvy
      The following actionscript code mimics a heart monitor, but the functions draw the lines too fast. I need to know how to control the speed of an overall function or the onEnterFrame event handler. Using the good old var += growthRate is not going to work in this case because I have diagonal lines.

      var count = 0;
      var first_x = 0; // starting x position
      var first_y = 120; // starting y position
      var growth_x = 50; // line growth rate

      _root.createEmptyMovieClip("line", 1); // line movieclip

      function Pulse () {
      line.moveTo(first_x, first_y);
      second_x = first_x+20;
      second_y = first_y-90;
      line.lineTo(second_x, second_y);
      third_x = first_x+40;
      third_y = first_y-15;
      line.lineTo(third_x, third_y);
      fourth_x = first_x+50;
      fourth_y = first_y-40;
      line.lineTo(fourth_x, fourth_y);
      fifth_x = first_x+70;
      fifth_y = first_y;
      line.lineTo(fifth_x, fifth_y);
      first_x = first_x+70;
      }

      function Monitor () {
      // horizontal line movement
      line.lineStyle(2, 0x0000FF, 100);
      line.moveTo(first_x , first_y);
      line.lineTo(first_x+growth_x , first_y);
      first_x = first_x+growth_x;
      Pulse ();
      }

      onEnterFrame = function () {
      Monitor ();
      }
        • 1. Re: Slowing the speed of a function
          Jason_Savvy Level 1
          Well I found out about setInterval but I cannot get the damn thing to work. PLEASE HELP!

          var count = 0;
          var first_x = 0; // starting x position
          var first_y = 120; // starting y position
          var growth_x = 50; // line growth rate

          _root.createEmptyMovieClip("line", 1); // line movieclip

          monitorInterval = setInterval(Monitor, 10000);
          pulseInterval = setInterval(Pulse, 10000);

          function Pulse () {
          line.moveTo(first_x, first_y);
          second_x = first_x+20;
          second_y = first_y-90;
          line.lineTo(second_x, second_y);
          third_x = first_x+40;
          third_y = first_y-15;
          line.lineTo(third_x, third_y);
          fourth_x = first_x+50;
          fourth_y = first_y-40;
          line.lineTo(fourth_x, fourth_y);
          fifth_x = first_x+70;
          fifth_y = first_y;
          line.lineTo(fifth_x, fifth_y);
          first_x = first_x+70;
          clearInterval(pulseInterval);
          }

          function Monitor () {
          // horizontal line movement
          line.lineStyle(2, 0x0000FF, 100);
          line.moveTo(first_x , first_y);
          line.lineTo(first_x+growth_x , first_y);
          first_x = first_x+growth_x;
          Pulse ();
          clearInterval(monitorInterval);
          }

          onEnterFrame = function () {
          Monitor ();
          }
          • 2. Re: Slowing the speed of a function
            kglad Adobe Community Professional & MVP
            you're calling Monitor and Pulse after 10 seconds with your setInterval() functions (and then you're terminating those loops) and you're calling monitor at your frame rate with that onEnterFrame() loop. that doesn't make much sense, but it shouldn't cause a problem unless that's not what you want.