-
How do I count up from a certain date?
I want to do a thing where a number is displayd, and it represents the number of days that has passed since I started the date.
Or to put it in another way, I put the certain date in the actionscript, and it displays how many days had passed since that date, on the main stage, inside a text box.
I'm using Flash MX.
you paid 1500$ for a computer just to read signatures?
-
Senior Member
code:
oldDate = new Date(2004,1,23); // february 23
newDate = new Date(); // today
elapsed = newDate - oldDate; // elapsed milliseconds
// some sample information
trace("old date: " + oldDate);
trace("new date: " + newDate);
trace(elapsed + " milliseconds elapsed");
trace(Math.floor(elapsed/1000) + " seconds elapsed");
trace(Math.floor(elapsed/(1000*60)) + " minutes elapsed");
trace(Math.floor(elapsed/(1000*60*60)) + " hours elapsed");
trace(Math.floor(elapsed/(1000*60*60*24)) + " days elapsed");
trace(Math.floor(elapsed/(1000*60*60*24*7)) + " weeks elapsed");
// to put it in a text box:
daysElapsedTextBox.text = Math.floor(elapsed/(1000*60*60*24));
Last edited by jbum; 05-31-2004 at 01:41 PM.
-
I put in the instance name "daysElapsedTextBox" without the quotations, and changed the code to the following:
oldDate = new Date(2004, 4, 31);
// february 23
newDate = new Date();
// today
elapsed = newDate-oldDate;
// elapsed milliseconds
// some sample information
trace("old date: "+oldDate);
trace("new date: "+newDate);
trace(Math.floor(elapsed/(1000*60*60*24))+" days elapsed");
// to put it in a text box:
daysElapsedTextBox.text = Math.floor(elapsed/(1000*60*60*24));
And I got the following error message when I opened the flash movie, in the debug window thingie:
old date: Mon May 31 00:00:00 GMT+0200 2004
new date: Mon May 31 20:43:29 GMT+0200 2004
0 days elapsed
It's called "Output" instead of "debug", but the window is just annoying.
Last edited by MO(D)VDO; 05-31-2004 at 01:52 PM.
you paid 1500$ for a computer just to read signatures?
-
Senior Member
The instance name of the textbox would be
daysElapsedTextBox
(or you can use something shorter, and then modify the code to match).
I don't use variable names with textboxes. Instead I've written the code to modify the .text property. So you can leave the variable name blank.
-
I appreciate your help very, very much, but more help is needed.
I edited the post above.
Edit: oh okay, it doesn't do that in the movie itself.
You rock.
How do you cause the output window to shut the hell up?
Last edited by MO(D)VDO; 05-31-2004 at 01:54 PM.
you paid 1500$ for a computer just to read signatures?
-
Senior Member
The trace commands (which send text to the output window) may be removed to shut up the output window.
They were intended to illustrate how to manipulate the numbers. 
Since you're not familiar with it, you should know that the trace() command is VERY useful for learning actionscript and debugging your scripts.
* * *
Are you still getting "0 days elapsed" though? Zero and not some other number? If so, change this line:
elapsed = newDate-oldDate;
to this:
elapsed = newDate.getTime() - oldDate.getTime();
Last edited by jbum; 05-31-2004 at 02:01 PM.
-
no no, all is good.
you own.
you paid 1500$ for a computer just to read signatures?
-
-
Thanks jbum for showing clearly how to show the total number of seconds since a date:
trace(Math.floor(elapsed/1000) + " seconds elapsed");
I was wondering if anyone could help me make it countup live. All I want to be able to show is the continuous number of seconds passed since a certain date but it's a bit beyond me!
Many thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|