Copy link to clipboard
Copied
Here is the code that I have so far, I need to create a stop for the timer so that it stops when the timer reaches 00:00. As it stands, the timer hits 00:00 then goes straight to 0-1:59. I'm lost on how to get it to stop, any help or feedback is greatly appreciated.
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.utils.Timer;
import flash.text.TextFormatAlign;
public class Main extends Sprite
{
public var timer:Timer = new Timer(1000);
public var txtClock:TextField = new TextField();
public var min:int = 0;
public var sec:int = 05;
public var txtFormat:TextFormat = new TextFormat();
public function Main()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
timer.start();
timer.addEventListener(TimerEvent.TIMER, changeClock);
txtClock.x = 100;
txtClock.y = 20;
addChild(txtClock);
txtClock.defaultTextFormat = txtFormat;
txtFormat.bold = true;
txtFormat.size = 18;
txtFormat.font = "Arial Black";
txtFormat.color = 0xFF0000;
txtFormat.align = TextFormatAlign.CENTER;
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
}
private function changeClock(e:TimerEvent):void
{
var formatSec:String;
var formatMin:String;
sec -= 1;
if (sec == 0)
{
min -= 1;
sec = 59;
}
if (sec < 10)
{
formatSec = "0" + String(sec);
}
else
{
formatSec = String(sec);
}
if (min < 10)
{
formatMin = "0" + String(min);
}
else
{
formatMin = String(min);
}
txtClock.text = String(formatMin + " : " + formatSec);
txtClock.border = true;
txtClock.width = 200;
txtClock.height = 30;
txtClock.borderColor = 0x0000FF;
txtClock.setTextFormat(txtFormat);
}
Copy link to clipboard
Copied
After you write to the textfield you can check to see if the text it contains == "00:00" and if so stop the timer
Find more inspiration, events, and resources on the new Adobe Community
Explore Now