7 Replies Latest reply on Apr 28, 2007 8:08 AM by tomnicholson

    angles with actionscript

    tomnicholson
      Hi

      i wonder if someone can help

      i'm sorry, i'm pretty new to flash, but someone wants me to make a program where there is a horizontal line and a vertical line.

      the user should be able to "grab" the top of the vertical line, and move it around, the bottom of the line should be snapped to the horizontal line, and a text box will display the angle between the two...

      any ideas?

      i have a rough idea but i've never done anything with angles before...

      thanks
      tom
        • 1. Re: angles with actionscript
          Level 7

          Hi tom,

          QAD (this makes the whole line clickable, but demonstrates the idea):

          have a movieclip containing a horizontal line.
          place it onstage twice with the two instancenames:
          vert_mc
          and
          hor_mc
          then add a dynamic textfield with the instancename deg_txt.

          And place this script in the first frame (watch for wrapping):

          import flash.geom.*

          vert_mc._rotation = -90;

          var origin:Point = new Point(hor_mc._x, hor_mc._y);

          vert_mc.onPress = function(){
          this.onEnterFrame = function(){
          var calced_x:Number = _xmouse - origin.x ;
          var calced_y:Number = _ymouse - origin.y ;
          var degrees:Number = Math.atan2(calced_y, calced_x) * (180 / Math.PI);
          vert_mc._rotation = degrees;
          deg_txt.text = degrees;
          };
          };
          vert_mc.onRelease = function(){
          delete this.onEnterFrame;
          };

          Manno

          tomnicholson wrote:
          > Hi
          >
          > i wonder if someone can help
          >
          > i'm sorry, i'm pretty new to flash, but someone wants me to make a program
          > where there is a horizontal line and a vertical line.
          >
          > the user should be able to "grab" the top of the vertical line, and move it
          > around, the bottom of the line should be snapped to the horizontal line, and a
          > text box will display the angle between the two...
          >
          > any ideas?
          >
          > i have a rough idea but i've never done anything with angles before...
          >
          > thanks
          > tom
          >

          --
          ----------
          Manno Bult
          http://www.aloft.nl
          manno@xs4all.nl
          • 2. Re: angles with actionscript
            tomnicholson Level 1
            cheers dude, great help

            needs a bit of tweaking to get exactly how i want it, but what you gave was superb.

            cheers
            • 3. Re: angles with actionscript
              Level 7
              you're welcome

              tomnicholson wrote:
              > cheers dude, great help
              >
              > needs a bit of tweaking to get exactly how i want it, but what you gave was superb.
              >
              > cheers

              --
              ----------
              Manno Bult
              http://www.aloft.nl
              manno@xs4all.nl
              • 4. Re: angles with actionscript
                tomnicholson Level 1
                ah, hang on, it doesn't drop the line after you release the mouse, do you know the code for that?
                • 5. Re: angles with actionscript
                  Level 7
                  Mmmm, it should if you let go of the mouse right over the line, but you
                  can release outside of the line too. Forgot...

                  Make it:
                  vert_mc.onRelease = vert_mc.onReleaseOutside = function(){
                  delete this.onEnterFrame;
                  };

                  in the last bit of the code.
                  Manno

                  tomnicholson wrote:
                  > ah, hang on, it doesn't drop the line after you release the mouse, do you know the code for that?

                  --
                  ----------
                  Manno Bult
                  http://www.aloft.nl
                  manno@xs4all.nl
                  • 6. Re: angles with actionscript
                    shikozel Level 1
                    add that:

                    vert_mc.onRelease = vert_mc.onReleaseOutside=function(){
                    delete this.onEnterFrame;
                    };
                    • 7. Re: angles with actionscript
                      tomnicholson Level 1
                      yeah thats done it

                      cheers guys!