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

flash on 2013-11-6

Get Adobe Flash player
by mutantleg 05 Nov 2013
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/tcv5
 */

package {
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            
            rx = 100;
            ry = 100;
            tow = new xTower();
            tow.cx = 320;
            tow.cy = 240;
            
            stage.addEventListener(MouseEvent.MOUSE_DOWN, mdown);
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public function mdown(e:MouseEvent):void
        {
            tow.tx = stage.mouseX;
            tow.ty = stage.mouseY;
            tow.mode = 1;
        }//mdown
        
        public var rx:Number = 0;
        public var ry:Number = 0;
        public var tow:xTower;
        
        public function onEnter(e:Event):void
        {
            var a:xTower;
            a = tow;
            
            var dist:Number;
            var dx:Number; 
            var dy:Number;
            
            graphics.clear();
            graphics.lineStyle(2, 0);
            graphics.drawCircle(a.cx, a.cy, 12);
            graphics.drawCircle(rx, ry, 8);
            
            graphics.lineStyle(1,0,0.2);
            graphics.drawCircle(rx,ry, 200);
            graphics.drawCircle(rx,ry, 80);
            
            
            dx = a.cx - rx;
            dy = a.cy - ry;
            dist = Math.sqrt(dx*dx+dy*dy);
            if (dist < 100)
            {
               graphics.moveTo(a.cx,a.cy);
               graphics.lineTo(rx,ry);   
            }
            
            if (a.mode == 0)
            {
               if (dist < 200)
               if (dist > 80)
               {
                 a.mode = 2;
                 a.tx = rx; a.ty = ry;   
               }   
            }
            
            
            
            dx = a.tx - a.cx;
            dy = a.ty - a.cy;
            dist = Math.sqrt(dx*dx+dy*dy);
            if (dist == 0) { dist =0.000000001;}
            dx /= dist;
            dy /= dist;
            var ms:Number;
            ms = 4;
            dx *= ms;
            dy *= ms;
            
            if (a.mode == 1)
            if (dist < 30) { a.mode = 0; }
            
            if (a.mode == 2)
            if (dist < 80) { a.mode = 0; }
            
            if (a.mode > 0)
             { 
              a.cx += dx; a.cy += dy;
              graphics.moveTo(a.cx, a.cy);
              graphics.lineTo(a.tx,a.ty);
             }
            
        }//onenter
        
    }//classend
}

internal class xTower
{
    public var cx:Number = 0;
    public var cy:Number = 0;
    public var tx:Number = 0;
    public var ty:Number = 0;
    public var target:int = 0;
    public var mode:int = 0;
    
}//xtower