draws a single line with a random stroke style every 250 milliseconds. It uses clear( ) to erase the previously drawn line. : Timer « Animation « Flash / Flex / ActionScript






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));
    }
  }
}

        








Related examples in the same category

1.Creating a Timer
2.Repeating a Task over Time
3.Two timers are set, one for a square sprite and one for a circle sprite
4.Change text value in a TextField in a timer
5.Post-Event Updates for Timer Events
6.Creating Symbols Within Flash CS3
7.Defers the call to the deferredMethod( ) method for five seconds: