Mega Code Archive

 
Categories / Flash ActionScript / Animation
 

Draws a single line with a random stroke style every 250 milliseconds It uses clear( ) to erase the previously drawn line

package {   import flash.display.*;   import flash.utils.*;   import flash.events.*;   public class Main extends Sprite {     private var s:Shape;     public function Main(  ) {       s = new Shape(  );       addChild(s);       var t:Timer = new Timer(250);       t.addEventListener(TimerEvent.TIMER, timerListener);       t.start(  );     }     private function timerListener (e:TimerEvent):void {       s.graphics.clear(  );       s.graphics.lineStyle(random(1, 10), random(0, 0xFFFFFF));       s.graphics.moveTo(random(0, 550), random(0, 400));       s.graphics.lineTo(random(0, 550), random(0, 400));     }     public function random (minVal:int, maxVal:int):int {       return minVal + Math.floor(Math.random(  ) * (maxVal + 1 - minVal));     }   } }