Reply LinkBack Thread Tools Search this Thread
Old 02-04-2008, 02:39   #1 (permalink)
thomasvining
Senior Member
 
thomasvining's Avatar
 
Join Date: Jul 2005
Location: Tokyo
Posts: 322
Send a message via MSN to thomasvining
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 dateate = new 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
  Reply With Quote
Old 02-04-2008, 04:13   #2 (permalink)
d*d
Senior Member
 
d*d's Avatar
 
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?
  Reply With Quote
Old 02-04-2008, 04:35   #3 (permalink)
thomasvining
Senior Member
 
thomasvining's Avatar
 
Join Date: Jul 2005
Location: Tokyo
Posts: 322
Send a message via MSN to thomasvining
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
  Reply With Quote
Old 02-04-2008, 04:51   #4 (permalink)
d*d
Senior Member
 
d*d's Avatar
 
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)
  Reply With Quote
Old 02-04-2008, 05:00   #5 (permalink)
thomasvining
Senior Member
 
thomasvining's Avatar
 
Join Date: Jul 2005
Location: Tokyo
Posts: 322
Send a message via MSN to thomasvining
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
  Reply With Quote
Old 02-04-2008, 05:05   #6 (permalink)
JonoMarshall
Day-Glo Jazz Monkey
 
JonoMarshall's Avatar
 
Join Date: Mar 2007
Location: Shoreditch, London
Posts: 811
Quote:
(set your intervals up so they happen each frame)

...use an onEnterFrame function to repeatedly add/update the difference between the two times.
__________________
  Reply With Quote
Old 02-04-2008, 05:12   #7 (permalink)
d*d
Senior Member
 
d*d's Avatar
 
Join Date: Oct 2004
Location: Bristol
Posts: 2,804
Quote:
Originally Posted by JonoMarshall
...use an onEnterFrame function to repeatedly add/update the difference between the two times.

that might be better
  Reply With Quote
Old 02-04-2008, 06:08   #8 (permalink)
thomasvining
Senior Member
 
thomasvining's Avatar
 
Join Date: Jul 2005
Location: Tokyo
Posts: 322
Send a message via MSN to thomasvining
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 dateate = new 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
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8