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-5-16

Get Adobe Flash player
by mutantleg 16 May 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/3wrl
 */

package {
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            
            hx = px;
            hy = py;
            
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public var px:Number = 200;
        public var py:Number  = 100;
        
        public var ax:Number = 200-16;
        public var ay:Number = 150;
        
        public var bx:Number = 200+16;
        public var by:Number = 150;
        
        public var step:int = 0;
        public var wstep:Number = 64; //step length
        public var hstep:Number = wstep * 0.5; //half step
        public var uy:Number = 4; //stepheight
        public var wx:Number = 0; //pixels moved
        
        public var dx:Number = 4; //dir (and speed)
        
        public var hx:Number = 200;
        public var hy:Number = 100;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            
            graphics.lineStyle(2,0);
            graphics.drawCircle(px,py,16);
            
            graphics.lineStyle(2,0xFF0000);
            graphics.drawCircle(ax,ay,8);
            
            graphics.lineStyle(2,0xFF);
            graphics.drawCircle(bx,by,8);
            
            
            
            if (step  == 0)
            {
              ax += dx;
              if (ax > 350) { dx = -4;}
              if (ax < 50) { dx = 4;}
              
              if (wx < hstep)
              {   ay -= uy; } else {ay += uy;}
              
              wx += 4;
              if (wx >= wstep) { wx = 0; step = 1; by = 150;}   
                }
                else
             if (step == 1)
             {
                bx += dx;
                if (bx > 350) { dx = -4;}
                if (bx < 50) { dx = 4;}
                
               if (wx < hstep)
               { by -= uy; } else { by += uy;}
                wx += 4;   
                 if (wx >= wstep) {wx = 0; step = 0; ay = 150;}
              }
            
            if (step != 0 && ay < 150) { ay += 2; if (ay > 150) { ay = 150;}}
            if (step != 1 && by < 150) { by += 2; if (by > 150) {by = 150;}}
            
            px = (ax + bx) * 0.5;
            py = (ay + by) *0.5 - 40;
            
           // if (px >= 350) { dx = -4; }
           // if (px <= 50) { dx =  4;}
            
              graphics.lineStyle(3,0);
              graphics.moveTo(px+16,py);
              graphics.lineTo(ax,ay-8);
              
              graphics.moveTo(px-16, py);
              graphics.lineTo(bx, by-8);
              
              hx += ((px+dx*4) - hx) * 0.2;
              hy += ((py-8) - hy) * 0.1;
              
              graphics.drawCircle(hx,hy, 12);
            
         }//onenter
        
    }//classend
}