主题:  《深入flash5编程》中的一个例子

mike_5d

职务:普通成员
等级:1
金币:0.0
发贴:52
注册:2001/3/5 15:04:38
#12002/3/17 10:06:35
这是《深入flash5编程》中的一个例子(P15),就会使currentdate文本框显示的月份总是比fulldate文本框显示的小一个月.
观察关于日期的显示的
days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
todaydate = timedate.getDate();
day = timedate.getDay();
dayname = days[day];
currentdate = todaydate+"/"+month+"/"+year;
fulldate = dayname+" "+todaydate+" "+monthname+" "+year;
几个语句就不难发现应该在months = new Array('January','February','March','April','May','June','July','August','September','Octorber','November','December');中添加'December'
但如此改过后任不行,我以为是数组下标是从零开始的,所以应该多加一个'December'。可只有month = timedate.getMonth();变为 month = timedate.getMonth()+1;的话,才可完全正常。
不知何故?如有兴趣,请将http://zfj19.home.chinaren.com/clock.rar下载后看看!
或者http://zfj19.home.chinaren.com/clock.fla 和http://zfj19.home.chinaren.com/clock1.fla
(只是clock.rar的解压缩!)


炎杀黑龙波!

mike_5d

职务:普通成员
等级:1
金币:0.0
发贴:52
注册:2001/3/5 15:04:38
#22002/3/17 10:09:13
忘了贴出源文件了
onClipEvent (load) {
days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
months = new Array('January','February','March','April','May','June','July','August','September','Octorber','November','December');
timedate = new Date;
}
onClipEvent (enterFrame) {
hour = timedate.getHours();
minutes = timedate.getMinutes();
seconds = timedate.getSeconds();
todaydate = timedate.getDate();
day = timedate.getDay();
dayname = days[day];
month = timedate.getMonth();
monthname = months[month];
year = timedate.getFullYear();
if (length(minutes)==1) {
minutes = "0"+minutes;}
if (length(seconds)==1) {
seconds = "0"+seconds;}
currenttime = hour+":"+minutes+":"+seconds;
currentdate = todaydate+"/"+month+"/"+year;
fulldate = dayname+" "+todaydate+" "+monthname+" "+year;
delete timedate;
timedate = new Date;
}