clock.lzx
<library>
<include href="resources.lzx"/>
<font name="Kgr">
<face src="kroeger-6-plain-regular.ttf"/>
</font>
<class name="viewframe" extends="view">
<attribute name="aframe" value="0
"/>
<method name="setAttribute" args="a,v">
if ( a == "aframe" ) {
this.setAttribute('frame', Math.round( v ));
}
super.setAttribute( a, v );
</method>
</class>
<class name="clock" resource="clockbkgnd">
<attribute name="height" value="${this.width}"/>
<attribute name="act_height" value="${this.unstretchedheight}"/>
<attribute name="act_width" value="${this.unstretchedwidth}"/>
<attribute name="lasthour" value="0
"/>
<attribute name="lastminute" value="0
"/>
<attribute name="lastsecond" value="0
"/>
<attribute name="timezoneoffset" value="0
"/>
<text font="Helmet,Arial,Helvetica,sans-serif" fontsize="9" name="dayandampm" y="${parent.height/2 + 14}" visible="false">SUN AM
<handler name="ontext">
this.setX(parent.width/2 - Math.floor(this.getTextWidth()/2.0));
this.setAttribute('visible', true);
</handler>
</text>
<viewframe name="hh" resource="hourhand"/>
<viewframe name="mh" resource="minutehand"/>
<viewframe name="sh" resource="secondhand"/>
<view resource="cap"/>
<view resource="glasshilite"/>
<method name="setCurrentTime">
// Get the current date and time local to this machine
var currentTimeObj = new Date();
// Tranlsate the time to the cities local time
currentTimeObj.setTime(currentTimeObj.getTime() + currentTimeObj.getTimezoneOffset()*60*1000); // UTC time
currentTimeObj.setTime(currentTimeObj.getTime() + + this.timezoneoffset*60*60*1000); // local to city
var hourNum = currentTimeObj.getHours();
// change time and get day
var dayNum = currentTimeObj.getDay();
var dayArray = ["Sun","Mon","Tue","Wed","Thur","Fri","Sat"];
// Get PM or AM
if (hourNum > 11) {
hourNum-=12; // for clock representation
var hourLabel="PM";
} else {
var hourLabel="AM";
}
this.dayandampm.setText(dayArray[dayNum] + " " + hourLabel);
// Get Minutes and Seconds
var minNum=currentTimeObj.getMinutes();
var secNum=currentTimeObj.getSeconds();
// now vsiually update the hands of the clock
this.updateHands( hourNum, minNum, secNum );
</method>
<method name="updateHands" args="hour, min, sec">
// Debug.debug("updateHands:", hour, min, sec );
var dur = 700;
if ( this.lasthour != hour ){
this.hh.animate('aframe', hour, 1000 );
this.lasthour = hour;
}
if ( this.lastminute != min ){
this.mh.animate('aframe', min, 1000 );
this.lastminute = min;
}
if ( this.lastsecond != sec ){
this.sh.setAttribute('aframe', sec);
this.lastsecond = sec;
}
/*
if ( this.lastminute != minNum*6 ){
this.lastminute = minNum*6;
this.mh.animate('rotation',this.lastminute,dur);
this.mhs.animate('rotation',this.lastminute,dur);
}
this.shs.setAttribute('rotation',secNum*6,dur);
this.sh.setAttribute('rotation',secNum*6,dur);
*/
</method>
<handler name="onsecond" reference="secondtimer">
this.setCurrentTime();
</handler>
<method name="setTimeZone" args="tzo">
this.timezoneoffset = tzo;
</method>
</class>
</library>
Cross References
Includes
Classes