In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: flash on 2010-9-13

Get Adobe Flash player
by say0 15 Sep 2010
    Embed
/**
 * Copyright say0 ( http://wonderfl.net/user/say0 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/FZg5
 */

// forked from say0's flash on 2010-9-13
package {
    import flash.display.Sprite;
    import flash.geom.Point;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    
    [SWF(width="800",height="400",frameRate="60")]
    
    public class FlashTest extends Sprite {
        
        
        
        private var p1:Point = new Point(Math.random()*800,Math.random()*400);
        private var p2:Point = new Point(Math.random()*800,Math.random()*400);
        private var p3:Point =new Point(Math.random()*800,Math.random()*400);
        
        private var thumb1:Sprite =new Sprite();
        private var thumb2:Sprite = new Sprite();
        private var thumb3:Sprite = new Sprite();
        
        private var lines:Sprite = new Sprite(); 
        private var tf:TextField = new TextField();
        private var tf1:TextField = new TextField();         
        public function FlashTest() {
            addChild(tf);
            addChild(tf1);
            tf.y=20
            tf1.y=50;
            init()
            
            
            
        }
        
        private function init():void{
            
            thumb1.x=p1.x;
            thumb1.y=p1.y;
            drawThumb(thumb1,0xff0000);
            thumb2.x=p2.x;
            thumb2.y=p2.y;
            drawThumb(thumb2,0x00ff00);
            thumb3.x=p3.x;
            thumb3.y=p3.y;
            drawThumb(thumb3,0x0000ff);
            
            drawLines();
            addChild(lines);
            //addEventListener(Event.ENTER_FRAME,frameHdl);
        }

        private function drawThumb(thumb:Sprite,c:uint=0x777777):void{
            
            var sp:Sprite = thumb;
            //sp.graphics.lineStyle(1,0,1);
            sp.graphics.beginFill(c);
            sp.graphics.drawCircle(0,0,10);
            sp.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHdl);
            sp.addEventListener(MouseEvent.MOUSE_UP,mouseUpHdl);
            addChild(sp);
        }
        
        private function mouseDownHdl(e:MouseEvent):void{
            e.target.startDrag();
            //tf.text= e.target.x;
            stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHdl);
        }
        
        private function mouseUpHdl(e:MouseEvent):void{
            e.target.stopDrag();
            stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHdl);
        }

        
        private function mouseMoveHdl(e:MouseEvent):void{
            
            setPoint();
            drawLines();
            calAngle()
           //tf.text = e.target.x;
           
        }
        
        private function calAngle():void{
            var n:Number=0;
            var n2:Number=0;
            n = Math.atan2((p1.y-p2.y),(p1.x-p2.x)) ;
            n2 = n*180/Math.PI; 
            thumb3.x=p2.x + Math.cos(n)*Point.distance(p2,p3);
            thumb3.y=p2.y + Math.sin(n)*Point.distance(p2,p3);
            tf.text= "radians"+n; 
            tf1.text= "degrees"+n2;
        }

        

        
        private function setPoint():void{
            p1.x = thumb1.x;
            p1.y = thumb1.y;
            p2.x = thumb2.x;
            p2.y = thumb2.y;
            p3.x = thumb3.x;
            p3.y = thumb3.y;
        }

        
        private function drawLines():void{
            //tf.text = String(p1.x);
            lines.graphics.clear();
            lines.graphics.lineStyle(1,0,1);
            lines.graphics.moveTo(p1.x,p1.y);
            lines.graphics.lineTo(p2.x,p2.y);
            lines.graphics.lineTo(p3.x,p3.y);
        }
   
    }
}