Date objects and arrays (system clock retreival...)

ok heres the code that i have on a MC…

  onClipEvent (enterFrame) {
    hours = getHours();
    minutes = getMinutes();
    seconds = getSeconds();
    time = hours+":"+minutes+":"+seconds;
}

“time” is the variable of the dynamic text box that the time is supposed to be displayed in. ** It’s contained within the same MC as the code.That’s important** There was a tut where i saw the code for something like this on FLASHKIT, but it didn’t go into depth…i know I’m missin something (minor or major I’m not sure) can someone let me know wut it is…

its not really that important, i just was trying to learn variables and outputs…thanks for any help…the only thing that is displayed in the output box are the two colons in that last statement…

ok…it says it needs an operand in front of the “.getminutes” etc…@#%$ is an operand and how do i use it? thats wut I’m missin i think.

those are all methods of the Date object.

you need to creat a date object and then use it to execute those commands, then everything will be dandy!

now = new Date();
hour = now.getHours();
etc…

that code is relative to the movie that it’s on.

if you make your text box a movie, and then put the code on that movie, it should work.

i cut and pasted your code and it was dandy. you’ll probably want an if statement to add a “0” before the values if they’re less than 10 - turn 9 into 09.

My favorite clock:

mydate = new Date();
dayNum = mydate.getDay();
year = mydate.getFullYear();
monthNum = mydate.getMonth();
dateDay = mydate.getDate();
timeHours = mydate.getHours();
timeMinutes = mydate.getMinutes();
timeSeconds = mydate.getSeconds();
if (timeSeconds<10) {
timeSecs = “0”+timeSeconds;
}
if (timeSeconds>=10) {
timeSecs = timeSeconds;
}
if (timeMinutes<10) {
timeMins = “0”+timeMinutes;
}
if (timeMinutes>=10) {
timeMins = timeMinutes;
}
if (timeHours>=13) {
timeTotal = timeHours-12+":"+timeMins+":"+timeSecs;
}
if (timeHours<13) {
timeTotal = timeHours+":"+timeMins+":"+timeSecs;
}
if (timeHours>=12) {
time = timeTotal+" PM";
}
if (timeHours<12) {
time = timeTotal+" AM";
}
if (dayNum == 1) {
day = “Monday”;
}
if (dayNum == 2) {
day = “Tuesday”;
}
if (dayNum == 3) {
day = “Wednesday”;
}
if (dayNum == 4) {
day = “Thursday”;
}
if (dayNum == 5) {
day = “Friday”;
}
if (dayNum == 6) {
day = “Saturday”;
}
if (dayNum == 7) {
day = “Sunday”;
}
if (monthNum == 1) {
month = “January”;
}
if (monthNum == 2) {
month = “February”;
}
if (monthNum == 3) {
month = “March”;
}
if (monthNum == 4) {
month = “April”;
}
if (monthNum == 5) {
month = “May”;
}
if (monthNum == 6) {
month = “June”;
}
if (monthNum == 7) {
month = “July”;
}
if (monthNum == 8) {
month = “August”;
}
if (monthNum == 9) {
month = “September”;
}
if (monthNum == 10) {
month = “October”;
}
if (monthNum == 11) {
month = “November”;
}
if (monthNum == 12) {
month = “December”;
}
displayDate = day+","+" “+month+” “+dateDay+”, “+year+” "+time;

eyez,

you can avoid that plethora of if statements by using an array:

  
monthArray = ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"];
now = new Date();
month = monthArray[now.getMonth()];

same thing for day of the week.

ok, i couldn’t help it. … must … minimise … code …

 
months = ["jan","feb","mar","apr","may","jun","jul","aug","oct","nov","dec"];
weekdays = ["sun","mon","tue","wed","thu","fri","sat"];

function displayDate(){
   var wd,m,d,y,h,mi,s,t;
   var now = new Date();
   wd = weekdays[now.getDay()];
   m = months[now.getMonth()];
   d = now.getDate();
   y = now.getFullYear();
   h = now.getHours();
   mi = now.getMinutes();
   s = now.getSeconds();
   if(h>12){ h-=12; t="pm"; }else{ t="am"; }
   if(mi<10) mi = "0"+mi;
   if(s<10) s = "0"+s;
   return(wd+", "+m+" "+d+", "+y+" - "+h+":"+mi+":"+s+" "+t);
}

trace(displayDate());

very cool But the only problem that I am having is trying to display that function in a dynamic text box, this is what I get

[type function]

displayed but in the output window I get the entire correct response.

What did I miss?
do I have to make the function a varaible and then direct the box to that one?

Thanks, Matt

matt - yep, you’re on the right track.

instead of :

trace(displayDate());

write:

display = displayDate();

where display is the name of a dynamic text box.

supra, thanks, hope your coding is always that smart…i couldn’t be bothered, just cut’n’pasted…you’re still my AS god!

a thought: any way to duplicate a mc in such a way that it makes four of it’s own, placed clockwise all around it, so each time you rollover one of 'em, it makes 4 new ones around itself? any help appreciated…