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 2015-1-28

Get Adobe Flash player
by mutantleg 28 Jan 2015
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1IS1
 */

package {

    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
        
          stage.addEventListener(Event.ENTER_FRAME, onEnter);      
        }//ctor
        
        public var world_width:Number = 465+465+465;
        public var world_height:Number = 465+465+465;
        public var scr_width:Number = 465;
        public var scr_height:Number = 465;
        
        public var camx:Number = 0;
        public var camy:Number = 0;

        //world width needs to be at least 3X screen width or it doesnt work right
        public function getScrx(wx:Number):Number
        {
           if (camx > world_width-scr_width)
           if (wx < scr_width) { return (wx-camx)+world_width; }  
           
           if (camx < scr_width)
           if (wx > world_width-scr_width) { return (wx-world_width)-camx; }  
            
           return wx - camx; 
        }//getscrx
        
        //same: world height needs to be 3x screen height
        public function getScry(wy:Number):Number
        {
         if (camy > world_height-scr_height)
         if (wy < scr_height) { return (wy-camy)+world_height; }  
        
         if (camy < scr_height)
         if (wy > world_height-scr_height) { return (wy-world_height)-camy; }  
         return wy - camy;   
        }//getscry
        
        
        public function isOver(ax:Number, ay:Number, aw:Number, ah:Number
         ,bx:Number, by:Number, bw:Number, bh:Number):Boolean
        {
           var wh:Number; var hh:Number;
           wh = world_width * 0.5;
           hh = world_height * 0.5; 
           if (ax-bx > wh) { ax -= world_width; }
           if (bx-ax > wh) { bx -= world_width; }
           if (ay-by > hh) { ay -= world_height; } 
           if (by-ay > hh) { by -= world_height; }
            
           if (ax + aw < bx) { return false; }
           if (ay + ah < by) { return false; }
           if (bx + bw < ax) { return false; }
           if (by + bh < ay) { return false; }
            
           return true; 
        }//isover
        
        
        public function getAng(ax:Number, ay:Number, bx:Number, by:Number):Number
        {
           var wh:Number; var hh:Number;
           wh = world_width * 0.5;
           hh = world_height * 0.5; 
           if (ax-bx > wh) { ax -= world_width; } 
           if (bx-ax > wh) { bx -= world_width; }
           if (ay-by > hh) { ay -= world_height; } 
           if (by-ay > hh) { by -= world_height; }
           
           return Math.atan2(by-ay, bx-ax);
            
           return 0; 
        }//getang
        
        public var cx:Number = 320;
        public var cy:Number = 240;
        public var vx:Number = 0;
        public var vy:Number = 0;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            var ms:Number;      ms =8;
            graphics.drawRect(0,0, world_width/ms, world_height/ms);
            graphics.drawCircle(cx/ms,cy/ms, 4);
            graphics.drawRect(camx/ms,camy/ms,scr_width/ms,scr_height/ms);
   
            var edge:Number; edge = 150;
            var ps:Number;
            ps = 8;   
            if (stage.mouseX < edge) { vx = -ps; }
            else if (stage.mouseX > 465-edge) { vx = ps;}
            else { vx*=0.9;} 
            if (stage.mouseY < edge) { vy = -ps; }
            else if (stage.mouseY > 465-edge) { vy = ps;}
            else { vy*=0.9;} 
            //cx = 1024-43;
           // cx = world_width - 48;
          //  cy = world_height - 48;    
            
            
            cx += vx;      cy += vy;
            
            if (cx > world_width) { cx -= world_width; camx -= world_width; }
            if (cx < 0) { cx+= world_width; camx += world_width; }
            if (cy > world_height) { cy -= world_height; camy -= world_height; }
            if (cy < 0) { cy+= world_height; camy += world_height; }
          
            camx = camx +  ((cx-(scr_width*0.5)) - camx) *0.2;
            camy = camy +  ((cy-(scr_height*0.5)) - camy) *0.2;
            
            graphics.drawCircle(cx-camx,cy-camy, 16);
            graphics.drawRect(0-camx, 0-camy, world_width, world_height);

            
            
            var ax:Number; var ay:Number;
            var i:int;
             var sx:Number; var sy:Number;
            var ang:Number;
            ax = 30;
            ay = 50;
            for (i = 0; i < 64; i++)
            {
                ax += 244; if (ax > world_width) 
                { ax -= world_width; ay += 165; if (ay > world_height) { ay = 50; } }
 
                sx = getScrx(ax);        
                sy = getScry(ay); 
                //sx = ax - camx;       
                graphics.drawCircle(sx, sy, 8);
                graphics.drawCircle(ax/ms, ay/ms, 2);
          
                ang = Math.atan2(cy-ay, cx-ax);
                ang = getAng(ax,ay, cx, cy);
                graphics.moveTo(sx, sy);
                graphics.lineTo(sx+Math.cos(ang)*16, sy+(Math.sin(ang)*16) );      
                
            }//nexti
 
             var aw:Number; var ah:Number;
             aw  = 512; ah = 512;
             ax = world_width - 256; ay = world_width - 256;
             sx = getScrx(ax);     sy = getScry(ay); 
             graphics.drawRect(sx,sy,aw,ah);         
 
             if (isOver(cx,cy,2,2, ax,ay, aw,ah))
             {
               graphics.beginFill(0xFF, 0.1);
                 graphics.drawRect(sx,sy,aw,ah);                        
               graphics.endFill();   
             }
            
            
            
        }//onenter     
        
        
    }//classend
}