Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clock issues.

Status
Not open for further replies.

tivaelydoc

Technical User
Jul 4, 2007
6
0
0
Did I write this code wrong:

onClipEvent (enterFrame)
{
var time = new Date();
var month = time.getMonth()+1;
var day = time.getDate();
var hours = time.getHours();
var minutes = time.getMinutes();
var seconds = time.getSeconds();
var milliseconds = time.getMilliseconds();
this.hour._rotation = 30 * hours + minutes / 2;
this.min._rotation = 6 * minutes;
this.sec._rotation= 6 * seconds;
this.mil._rotation= .36 * milliseconds;
this.month._rotation= 30 * month;
this.day._rotation= 360/31 * date;
}

For some reason, all the hands work except the month and the day. How come?
 
Let's use today, January 21st, as an example.

[tt]var month = time.getMonth()+1;[/tt]

[tt]month[/tt] is 1, therefore:

[tt]this.month._rotation= 30 * month;[/tt]

[tt]this.month._rotation[/tt] is 30.

But I wouldn't use "month" as a variable name and a MovieClip name at the same time - it's a reserved word too. Don't you think it's confusing to use such a name???

[tt]var day = time.getDate();[/tt]

[tt]day[/tt] is 21.

[tt]this.day._rotation= 360/31 * date;[/tt]

[tt]this.day._rotation[/tt] is NaN, because the variable [tt]date[/tt] is not defined anywhere.

What you want is:
[tt]this.day._rotation= 360/31*day[/tt]

But again you are using a reserved word "day" for both variable name and MovieClip name. Not good.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top