forked from: flash on 2010-11-17

by Highly forked from flash on 2010-11-17 (diff: 6)
♥0 | Line 66 | Modified 2010-12-01 07:50:21 | MIT License
play

ActionScript3 source code

/**
 * Copyright Highly ( http://wonderfl.net/user/Highly )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oaXb
 */

// forked from Highly's flash on 2010-11-17
package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.display.Graphics;
    import flash.geom.Point;
    import flash.text.*
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.events.Event;
    import flash.utils.getTimer;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            var i:int=0;
            var d:Number=0;
            var ti:Timer = new Timer(200,0);
            var p1:Point = new Point(stage.stageWidth/2,stage.stageHeight/2);
            var p2:Point = new Point(0,0);
            var ln:Sprite = new Sprite();
            addChild(ln);
            ln.x = 0;
            ln.y = 0;
            ln.graphics.lineStyle(2,0x0000FF);
            ln.graphics.moveTo(p1.x,p1.y);
            ln.graphics.lineTo(p2.x,p2.y);
            ti.addEventListener(TimerEvent.TIMER, tf);
            var sq:Sprite = new Sprite();
            sq.x=0;
            sq.y=0;
            sq.graphics.lineStyle(2,0xFF0000);
            sq.graphics.drawRect(-5,-5,10,10);
            addChild(sq);
            function tf (e:TimerEvent):void{
                p2.x=Math.sin(getTimer())*stage.stageWidth;
                p2.y=Math.cos(getTimer())*stage.stageHeight;
                ln.graphics.clear();
                ln.graphics.beginFill(0xF0F0F0);
                ln.graphics.lineStyle(2,0x000000);
                ln.graphics.moveTo(p1.x,p1.y);
                ln.graphics.lineTo(p2.x,p2.y);
                ln.graphics.lineStyle(2,0x00FF00);
                ln.graphics.lineTo(p2.x,p1.y);
                ln.graphics.lineStyle(2,0x0000FF);
                ln.graphics.lineTo(p1.x,p1.y);
                ln.graphics.endFill();
                sq.x=((p2.x-p1.x)/2)+stage.stageWidth/2;
                sq.y=((p2.y-p1.y)/2)+stage.stageHeight/2;
                out1.x=sq.x+5;
                out1.y=sq.y+5;
                d= Math.round(Math.sqrt(((p2.x-p1.x)*(p2.x-p1.x))+((p2.y-p1.y)*(p2.y-p1.y))));
                out1.text = "("+Math.round(sq.x)+", "+Math.round(sq.y)+"), Length: "+d+"|"+(Math.sin(getTimer())*100);
                ++i;
            }            
            ti.start();
            var out1:TextField = new TextField();
            out1.x = 0;
            out1.y = 0;
            out1.text="";
            out1.selectable = false;
            out1.width = stage.stageWidth;
            out1.height = stage.stageHeight;
            out1.multiline = true;
            out1.wordWrap = true;
            addChild(out1);
            
        }
    }
}