flash on 2013-5-27

by mutantleg
♥0 | Line 57 | Modified 2013-05-27 19:17:01 | MIT License
play

ActionScript3 source code

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

package {
    import flash.utils.IDataInput;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            
            vecPart = new Vector.<xPart>(0, false);
            
            var a:xPart;
            var i:int;
        
            for (i = 0; i < 16; i++)
            { 
             a = new xPart();
             a.cx = 200 + i * 16;
             a.cy = 200;
             vecPart.push(a);  
            }
            
            a = vecPart[0];
            a.vx = 4;
            a.vy = 2;
                        
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public var vecPart:Vector.<xPart>;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            var i:int;
            var num:int;
            var a:xPart;
            var b:xPart;
            
           // a = vecPart[0];
            
           // a.cx += a.vx;
          //  a.cy += a.vy;
            
          
            
            
            
            num = vecPart.length;
            
            for (i = 1; i < num; i++)
            //for (i = num-1; i > 0; i--)
            {
                 a = vecPart[i];
                 b = vecPart[i-1];
                 
                 a.cx += (b.cx - a.cx) * 0.25;
                 a.cy += (b.cy - a.cy) * 0.25;
                 //a.cx = b.cx;
                 //a.cy = b.cy;
                 
                 graphics.drawCircle(a.cx, a.cy, 8);
                 
            }//nexti
            
             a = vecPart[0];
            
            a.cx += a.vx;
            a.cy += a.vy;
      
              graphics.drawRect(a.cx-8,a.cy-8,16,16);
            
              if (a.vx > 0 && a.cx > 400){ a.vx = -a.vx;  }
            if (a.vx < 0 && a.cx < 0){ a.vx = -a.vx;  }
            if (a.vy > 0 && a.cy > 400){ a.vy = -a.vy;  }
            if (a.vy < 0 && a.cy < 0){ a.vy = -a.vy;  }
        }//onenter
        
    }//classend
}

internal class xPart
{
 public var cx:Number = 0;
 public var cy:Number = 0;
 public var vx:Number = 0;
 public var vy:Number = 0;   
}