|
3 Timers
//Modified Version of Mustafa Basgun'work
//@ 7 Jan 2004
// Finding Time Passed by Using Date Object and Math.floor Method
// By: Mustafa Basgun (www.basgun.com)
// Date: 14th November 2002
// Level: Intermediate
// Initial values
// ActionScript counts months from 0 to 11; for example 03 means April
// Expression in startTime is like: (Year, Month, Day, Hour, Minutes, Seconds)
onClipEvent(enterFrame){
currentTime = new Date();
temp_hr = _root.arr_pdata[_root.timer_active].hour;
temp_min = _root.arr_pdata[_root.timer_active].min;
temp_sec = _root.arr_pdata[_root.timer_active].sec
temp_ttlsec = 1000*(new Number(temp_sec) + new Number(temp_hr*60*60) + new Number(temp_min * 60));
if(temp_hr != undefined && temp_min != undefined && temp_sec != undefined){
days = (currentTime - _root.startTime) / 1000 / 60 / 60 / 24;
days_round = Math.floor(days);
hours = (currentTime - _root.startTime + temp_ttlsec) / 1000 / 60 / 60 - (24 * days_round);
hours_round = Math.floor(hours);
minutes = (currentTime - _root.startTime + temp_ttlsec) / 1000 / 60 - (24 * 60 * days_round) - (60 * hours_round);
minutes_round = Math.floor(minutes);
seconds = ((currentTime - _root.startTime + temp_ttlsec) / 1000 - (24 * 60 * 60 * days_round) - (60 * 60 * hours_round) - (60 * minutes_round)) ;
seconds_round = Math.round(seconds);
} else{
days = (currentTime - _root.startTime) / 1000 / 60 / 60 / 24;
days_round = Math.floor(days);
hours = (currentTime - _root.startTime) / 1000 / 60 / 60 - (24 * days_round);
hours_round = Math.floor(hours);
minutes = (currentTime - _root.startTime) / 1000 / 60 - (24 * 60 * days_round) - (60 * hours_round);
minutes_round = Math.floor(minutes);
seconds = (currentTime - _root.startTime) / 1000 - (24 * 60 * 60 * days_round) - (60 * 60 * hours_round) - (60 * minutes_round);
seconds_round = Math.round(seconds);
}
if (seconds_round<10) { s = "0"+seconds_round; } else{s = seconds_round;}
if (minutes_round<10) { m = "0"+minutes_round; } else {m = minutes_round;}
if (hours_round<10) { h = "0"+hours_round; } else {h = hours_round;}
play();
timeTextField = (t = h+":"+m+":"+s);
_root.hour = hours_round;
_root.minute = minutes_round;
_root.sec = seconds_round;
// To create loop; do not forget to state gotoAndPlay(1) to the second frame.
}
//In the root level
//Default the Timer 1 is running
timer_active = 1
var hour:Number = new Number(0);
var minute:Number = new Number(0);
var sec:Number = new Number(0);
var arr_pdata:Array = [3];
arr_pdata[0] = ({hour:00,min:00,sec:00});
arr_pdata[1] = ({hour:00,min:00,sec:00});
arr_pdata[2] = ({hour:00,min:00,sec:00});
function resetTimer(atimer){
//stop the timer and store the time passed for future addition
startTime = new Date();
trace("p active timer: " + timer_active);
trace(hour+":"+minute+":"+sec);
arr_pdata[timer_active] = ({hour:hour,min:minute,sec:sec});
timer_active = atimer;
}
//Functions for btns
btn_line1.onRelease = function(){
_root.resetTimer(1);
};
btn_line2.onRelease = function(){
_root.resetTimer(2);
};
btn_line3.onRelease = function(){
_root.resetTimer(3);
};
Posted by: kk lau | website http://www.google.com |
/*
green analog clock with face and smoothly advancing watch
hands + digital display in flash MX, 2003 by www.advance-media.com
plz set document background color to black...
...place this script on a movieClip to get the hybrid clock
to advance, or place the content of the onClipEvent (load) {}
on frame 1 and on frame 3 write turn(); gotoAndPlay(2);
*/
onClipEvent (load) {
//in the beginning
for (i=0; i<60; i++) {
//drawing the face of the analog clock, 60 lines
//in a 360° circle each 5 min/sec and quarter of an hour with
//different line length, color and size
this.createEmptyMovieClip("lin_"+i, 100+i);
//create an empty for each line
this["lin_"+i]._rotation = i*6;
//60*6°=360°circle complete
if (i%5) {
//using modulo to draw different lines each 5 min
//modulo the rest of the division turns false 0
with (this["lin_"+i]) {
lineStyle(3, "0x009900", 100);
//shades of green
moveTo(0, 120);
//all lines start 120 px off center of the circle
lineTo(0, 116);
//short size
}
} else if (i%15) {
//if not dividable by 15 than draw the line for
//each hour or for each 5 minutes or for each 5 seconds
with (this["lin_"+i]) {
//mid size
lineStyle(4, "0x00cc00", 100);
moveTo(0, 120);
lineTo(0, 112);
}
} else {
//0,15,30,45 lines quarter of an hour
with (this["lin_"+i]) {
//long size
lineStyle(5, "0x00ff00", 100);
moveTo(0, -8);
moveTo(0, 120);
lineTo(0, 104);
}
}
}
this.createEmptyMovieClip("hour", 200);
//drawing the short hand, hour hand
with (this.hour) {
lineStyle(5, "0x00ff00", 100);
lineTo(0, -55);
}
this.createEmptyMovieClip("minu", 201);
//drawing the minute hand
with (this.minu) {
lineStyle(4, "0x00cc00", 100);
lineTo(0, -75);
}
this.createEmptyMovieClip("sec", 202);
//drawing the sweep hand, second hand
with (this.sec) {
lineStyle(3, "0x009900", 100);
lineTo(0, -95);
//-118);
}
//create a text field for the digital clock
this.createTextField("digit", 99, 100, 100, 200, 30);
digit.selectable = false;
greenFormat = new TextFormat();
//green, 23
greenFormat.color = 0x00ff00;
greenFormat.size = 23;
// function turn() pulse of the clock
function turn() {
mydate = new Date();
// reading the date object to check the time
ms = mydate.getMilliseconds();
//0-999
// milliseconds to move the second's hand smoothly
s = mydate.getSeconds();
//0-59
m = mydate.getMinutes();
//0-59
h = mydate.getHours();
//0-23
//turning the hands of the analog clock
this.sec._rotation = s*6+ms/1000*6;
//6°*60sec=360° plus 6° rotation per 1000 ms
this.minu._rotation = m*6+s/10;
//6°*60min=360° plus 6° rotation per 60 sec
this.hour._rotation = h*30+m/2;
//30°*12hour=360° plus 30° rotation per 60 min
// adding O digits to the digital clock
if (s<10) {
s = "0"+s;
}
if (m<10) {
m = "0"+m;
}
if (h<10) {
h = "0"+h;
}
t = h+":"+m+":"+s;
// cutting the digital string
digit.text = t;
//write digital clock in greenFormat
digit.setTextFormat(greenFormat);
}
}
onClipEvent (enterFrame) {
// turn, pulsed by the document frame rate, 2003 by www.advance-media.com
turn();
}
Posted by: Folko Langner | website http://www.advance-media.com |
/** * @author: Eric Feminella * @class: AnalogTimeFormatter * @url: http://www.ericfeminella.com * @param: constructor excepts 4 args * [parent mc, secondhand mc, minutehand mc, hourhand mc] * @usage: * var time:AnalogTimeFormatter = new AnalogTimeFormatter(this, secondhand_mc, minutehand_mc, hourhand_mc) */ class AnalogTimeFormatter { public var time:Date; public var seconds:Number; public var minutes:Number; public var hours:Number; public var parent, sec, min, hour:MovieClip; public function AnalogTimeFormatter(parent:MovieClip, sec:MovieClip, min:MovieClip, hour:MovieClip) { this.parent = parent; this.sec = sec; this.min = min; this.hour = hour; this.main(); } private function main():Void { var ref = this; this.parent.onEnterFrame = function():Void { ref.setAnalaogTime(); } } public function setAnalaogTime():Void { this.time = new Date(); this.seconds = this.time.getSeconds(); this.minutes = this.time.getMinutes(); this.hours = this.time.getHours(); this.hours += minutes / 60; this.seconds *= 6; this.minutes *= 6; this.hours *= 30; this.sec._rotation = this.seconds; this.min._rotation = this.minutes; this.hour._rotation = this.hours; } } Posted by: Eric Feminella | website http://www.ericfeminella.com |
/* -------------------------------------------------------------------------------- COUNTDOWN v1.0 [email protected] /optimized code -------------------------------------------------------------------------------- */ function Revert(zt){ var ts= (zt/1000);var tm= (ts/60);var to= (tm/60) days= Math.floor(to/24) hours= Math.floor(to-(24*days)) minutes= Math.floor((tm-(1440*days))-(60*hours)) seconds= Math.floor(((ts-(86400*days))-(3600*hours))-(60*minutes)) mseconds= new Date(zt).getMilliseconds() } function Zerofill(n, cifre){ if (length(n)<=cifre) { var dif= (cifre-length(n)) var j= 0 while (j<dif) { n= "0"+n j++ } } return (n) } function Timeformat(ms){ Revert(ms) Df= Zerofill(days, 2) Hf= Zerofill(hours, 2) Mf= Zerofill(minutes, 2) Sf= Zerofill(seconds, 2) MSf= Zerofill(mseconds, 3) } function DisplayRemaining() { //<codice> trace("intervallo relativo: "+Df+" giorni, "+Hf+" ore, "+Mf+" minuti, "+Sf+" secondi, "+MSf+" msecondi.") } function Elapsed() { Now= getTimer() Wait= gap-Now Revert(Wait) if ((Wait<=0) or ((days<=0)&&(hours<=0)&&(minutes<=0)&&(seconds<=0)&&(mseconds<=0))) { clearInterval(Countdown) Df= (Hf=(Mf=(Sf="00"))) MSf= "000" myDate= (Now=end) Wait= (gap=0) } Timeformat(Wait) DisplayRemaining() } // var y= "2004" var mt= "11" var d= "24" var h= "22" var mn= "59" var s= "55" var ms= "999" myDate= new Date(y, mt, d, h, mn, s, ms) var Ey= "2004" var Emt= "11" var Ed= "24" var Eh= "23" var Emn= "0" var Es= "0" var Ems= "0" end= new Date(Ey, Emt, Ed, Eh, Emn, Es, Ems) countevery= 10 // gap= end-myDate;Timeformat(gap) Countdown= setInterval(Elapsed, 10) // stop(); Posted by: fabio vergani | website http://www.kora.it |
/*This script goes on a MC and counts down to an event then executes code.
It uses getTimer which isn't alway the most reliable method but it works.*/
onClipEvent (load) {
wait = 5;
starTimer = true;
}
onClipEvent (enterFrame) {
if (starTimer) {
if (startTime == undefined) {
startTime = getTimer()/1000;
}
curTime = getTimer()/1000;
if ((curTime-startTime)>=wait) {
starTimer = false;
delete startTime;
// actions to do after time is up
trace ("bing!");
} else {
_root.timeRemaining = wait-(curTime-startTime);
}
}
}
//To get it to start counting down, just set movieClipName.startTimer = true;
Posted by: Jesse Stratford | website http://www.actionscript.org |

