AS3 Timer

Simple AS3 Timer Example with a stop button.

This movie requires Flash Player 9

package {
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;
 
public class TimerExample extends MovieClip {
 
	var sW:Number = stage.stageWidth;
	var sH:Number = stage.stageHeight;
 
	public function TimerExample() {
 
		//add timer mc
		var t:timer_mc = new timer_mc();
		addChild(t);
		t.x = sW*.5;
		t.y = sH*.5-50;
		//add btn
		var btn:b = new b();
		addChild(btn);
		btn.x = sW*.5;
		btn.y = sH*.5;
		var myTimer:Timer = new Timer(500);
		myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
		myTimer.start();
		btn.addEventListener(MouseEvent.CLICK, stopTimer,false,0);
		btn.buttonMode = true;
 
		function stopTimer(e:MouseEvent){
		myTimer.stop();
		}
 
		function timerHandler(et:TimerEvent) {
			trace(myTimer.currentCount);
			t.t_txt.text = ' myTimer.currentCount ' + myTimer.currentCount;
		}
		}
	}
}
This entry was posted in Uncategorized. Bookmark the permalink.

Comments


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">