//----------------------- // CLX_Timer Class // by Caspar Noetzli // www.crealogix.com // ---------------------- // //--------------------------- // CLX_Timer Constructor //--------------------------- CLX_Timer = function (objRef) { this.objRef = objRef; this.version = "v2003-11-20-001_clx"; // Countdown - Version needs to be checked and modified (noe) }; //--------------------------- // CLX_Timer getVersion //--------------------------- CLX_Timer.prototype.getVersion = function(objRef) { return ("CLX_Timer Class Version: "+this.version); }; // Initialisiere den Timer CLX_Timer.prototype.init = function(whichTimerMode, whichTimeLimit, whichInterval, whichVisibility, whichX, whichY) { // Setze den Timer modus (stopwatch oder countdown this.timerMode = whichTimerMode; // Setze eine allfällige Time-Limite (-1 für unbegrenzt) this.timeLimit = whichTimeLimit; // Setze das Zeit-überschritten Flag auf falsch this.timeLimitUeberschrittenFlag = false; // Setze das Intervall (milisekunden) in welchem der Timer "nachgeführt" wird. this.interval = whichInterval; // Setze den runMode this.runMode = false; // Wenn sichtbar erstelle ein display Textfield if (whichVisibility == true) { // Falls sichtbar Initialisiere das Text-display-Field tX = whichX; tY = whichY; _root.createTextField("timerDisplay_txt", _global.clx.levelCounter += 1, tX, tY, 60, 16); this.display_txt = _root.timerDisplay_txt; this.display_txt.background = true; this.display_txt.border = true; var tFormat_fmt = new TextFormat(); tFormat_fmt.align = "center"; tFormat_fmt.size = 10; tFormat_fmt.font = "verdana"; this.display_txt.setNewTextFormat(tFormat_fmt); this.display_txt.selectable = false; } this.resetTimer(); }; // CLX_Timer resetTimer CLX_Timer.prototype.resetTimer = function() { if (this.timerMode == "stopwatch") { this.display_txt.text = "00:00:00"; } if (this.timerMode == "countdown") { this.display_txt.text = this.timeLimit+":00"; } this.currentTime = 0; if (this.runMode == true) { this.stopTimer(); this.startTimer(); } }; // CLX_Timer startTimer CLX_Timer.prototype.startTimer = function() { if (this.runMode != true) { this.runMode = true; this.startTime = getTimer()-this.currentTime; this.timerID = setInterval(this, "updateTimer", this.interval); } }; // CLX_Timer stopTimer CLX_Timer.prototype.stopTimer = function() { this.runMode = false; clearInterval(this.timerID); }; // CLX_Timer getTime CLX_Timer.prototype.getTime = function() { return (this.currentTime); }; // CLX_Timer getMinutes CLX_Timer.prototype.getMinutes = function() { return (this.minutes); }; // CLX_Timer getSeconds CLX_Timer.prototype.getSeconds = function() { return (this.seconds); }; // CLX_Timer updateTimer CLX_Timer.prototype.updateTimer = function() { this.currentTime = getTimer()-this.startTime; this.seconds = Math.floor(this.currentTime/1000); // Wenn Countdown if (this.timerMode == "countdown") { this.seconds = (this.timeLimit)-this.seconds; } this.hours = Math.floor(this.seconds/3600); this.minutes = (Math.floor(this.seconds/60))%60; this.seconds = this.seconds%60; // Formatierung der Sekunden-Anzeige if (this.seconds<10) { var tSecDisplay = "0"+this.seconds; } else { var tSecDisplay = this.seconds; } //Option zur Formatierung der Minuten Anzeige mit preceeding 0 if (this.minutes<10) { var tMinDisplay = "0"+this.minutes; } else { var tMinDisplay = this.minutes; } //Option zur Formatierung der Stunden Anzeige mit preceeding 0 if (this.hours<10) { var tHourDisplay = "0"+this.hours; } else { var tHourDisplay = this.hours; } // Anzeige der formatierten Zeit this.display_txt.text = tHourDisplay+":"+tMinDisplay+":"+tSecDisplay; if (this.timeLimitUeberschrittenFlag == false || this.timeLimit == -1) { //if (this.timeLimit == this.getMinutes()) { if (this.currentTime>this.timeLimit*60*1000) { // Setze das timeLimitUeberschrittenFlag this.timeLimitUeberschrittenFlag = true; // Wenn Countdown stoppe den Timer if (this.timerMode == "countdown") { this.stopTimer(); this.display_txt.textColor = 0xFF0000; this.display_txt = "00:00"; } // Setze Farbe des Timers auf rot falls nicht *ohne* Timelimit if (this.timeLimit != -1) { this.display_txt.textColor = 0xFF0000; } } } }; // CLX_Timer checkTimeLimit CLX_Timer.prototype.checkTimeLimit = function() { return this.timeLimitUeberschrittenFlag; }; /*how to use this class myTimer = new CLX_Timer(this); trace (myTimer.getVersion()); // init (timerMode, timeLimit, intervall, visibility, x und y position falls visible myTimer.init("stopwatch", -1, 1000, true, 10, 10); start_btn.onRelease = function() { myTimer.startTimer(); }; stop_btn.onRelease = function() { myTimer.stopTimer(); }; reset_btn.onRelease = function() { myTimer.resetTimer(); };*/