3 Replies Latest reply on Jul 23, 2007 12:24 PM by craus

    Diagonal Moving Line

    Jason_Savvy
      I have been working on creating a heart rate monitor using ActionScript. I have figured out how to create a continuously moving horizontal line. I cannot seem to figure out how to change the line to make it move diagonally once the line reaches the 200 pixel mark. Here is the code I have so far:

      var count = 0; // for counting how many times Monitor function has run
      var x_l = 0; // starting x position
      var y_l = 100; // starting y position
      var speed = 7; // speed of line

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

      function Monitor () {
      // horizontal line movement
      line.moveTo(0, 100);
      line.lineStyle(2, 0x0000FF, 100);
      line.lineTo(x_l++ * speed, y_l);
      count = count++;
      // diagonal line movement below is not working
      if (count > 200) {
      y_l = y_1++;
      }
      }

      onEnterFrame = function () {
      Monitor ();
      }

      I know that I could hack my way through creating a heart monitor manually. However, this is not an option because I have to be able to adjust the rate based upon user actions.
        • 1. Re: Diagonal Moving Line
          Jason_Savvy Level 1
          Can anybody help me on this?
          • 2. Re: Diagonal Moving Line
            Jason_Savvy Level 1
            Well I have now figured out how to create the monitor animation. I now need to know how to slow it down!

            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 ();
            }
            • 3. Re: Diagonal Moving Line
              craus Level 1
              Jason
              Well I was interested in this subject and found your answer a few days ago. You want to draw lines with easing:
              http://www.flashgroup.net/forum/showthread.php?t=2714

              I experimented with your pulse shapes and placed it into the code.
              ***Please note I didn't write this code I only changed some values to make it work for you.***