| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Senior Member
|
Controlling time/numbers with flash
Hi there, I'm currently building a flash clock screensaver, and so far have the clock showing the time correctly with the following code. What I would like to do now is start the movie 12 hours back from the current time, then fast forward (count up correctly in digits) during say the first 200 frames of the movie up to the current time. Could anyone suggest an efficient way of doing this with as3? Thanks very much in advance for any advice/suggestions! ----------------------------------------------------------- FLASH CODE ----------------------------------------------------------- function localTime(Event) { var date var hourZero:String = new String(); var minuteZero:String = new String(); var secondZero:String = new String(); var h:Number = date.getHours(); var m:Number = date.getMinutes(); var s:Number = date.getSeconds(); if (s < 10) { secondZero = "0"; } else { secondZero = ""; } if (m < 10) { minuteZero = "0"; } else { minuteZero = ""; } if (h < 10) { hourZero = "0"; } else { hourZero = ""; } var displayTime:String = (hourZero + h + ":" + minuteZero + m + ":" + secondZero + s); textBox.text = displayTime; textBox.embedFonts = true; } stage.addEventListener(Event.ENTER_FRAME, localTime); ----------------------------------------------------------- Tokyocube.com - Japanese Designer Toys
|
|
|
|
|
|
#2 (permalink) |
|
Senior Member
Join Date: Oct 2004
Location: Bristol
Posts: 2,804
|
I would use the unix timestamp to get the time (another timestamp) 12 hours ago. I would then put code similar to what you have there into a function (with a timestamp argument) which creates a displayTime variable from that argument, then use setInterval with that function to display the times leading up to now make sense? |
|
|
|
#3 (permalink) |
|
Senior Member
|
hey d*d, thanks for the reply! That sounds perfectly correct, but as I've not used flash for a while, it'd be awesome if you could explain alittle more for me. I can get as far as having the 1st frame 12 hours behind, and the 50th frame at the current time, but could you explain how to use the setInterval function inbetween to fast-forward through the 12 hours? Would there be anyway for me to control the speed of the clock inbetween? Thanks again for your help! Tokyocube.com - Japanese Designer Toys
|
|
|
|
#4 (permalink) |
|
Senior Member
Join Date: Oct 2004
Location: Bristol
Posts: 2,804
|
get the timestamp for 12 hours ago and the one for now and subtract to get the difference, divide the difference by the number of frames and add that number each interval (set your intervals up so they happen each frame) |
|
|
|
#5 (permalink) |
|
Senior Member
|
ok, gotcha - thanks for that! probably spend a couple hrs figuring out how to actually do that, but it's better for me to learn! Tokyocube.com - Japanese Designer Toys
|
|
|
|
#8 (permalink) |
|
Senior Member
|
ok cool, thanks! I'm working on the code, as at least have the numbers moving up now, and the hour moving once the minutes run to 60, but was wondering if there's a simpler more elegant way of doing this, and also I'm still alittle clueless as to how to add the difference in time as there is 3 variables here (hr, min, secs): var count:Number = 0; var num:Number = 1; var hourNum:Number = 1; function increase(Event) { count += num; countTime(); } function countTime() { var date var hourZero:String = new String(); var minuteZero:String = new String(); var secondZero:String = new String(); var h:Number = date.getHours(); var m:Number = date.getMinutes() + count; var s:Number = date.getSeconds(); if (s < 10) { secondZero = "0"; } else { secondZero = ""; } if (m < 10) { minuteZero = "0"; } else { minuteZero = ""; } if (h < 10) { hourZero = "0"; } else { hourZero = ""; } if (m >= 59) { hourNum++; num = 1; count = 1; minuteZero = "0"; m = 0; } h = h + hourNum; var displayCountTime:String = (hourZero + h + ":" + minuteZero + m + ":" + secondZero + s); textCountBox.text = displayCountTime; textCountBox.embedFonts = true; } stage.addEventListener(Event.ENTER_FRAME, increase); Tokyocube.com - Japanese Designer Toys
|
|
![]() |