Creating a 12 hour digital clock in Animate CC in HTML5 Canvas
hello,
i have as3 code working 12 hour clock using dynamic text field , looking translate html5. i've found several examples of clock code in javascript, cannot seem translate working clock in animate cc.
can me translate as3 code working javascript/html5 animate cc?
//adds enter frame event dynamic text field.
thetime.addeventlistener(event.enter_frame,showtime);
function showtime(event:event):void {
//create new instance of date class.
var mytime:date = new date();
//this returns seconds, minutes , hour.
var theseconds=mytime.getseconds();
var theminutes=mytime.getminutes();
var thehours=mytime.gethours();
var ampm:string;
//displays am/pm depending on current hour.
if (thehours>=12) {
ampm="pm";
} else {
ampm="am";
}
//this subtracts 12 hour when greater 13.
if (thehours>=13) {
thehours=thehours-12;
}
if (thehours==0) {
thehours=thehours+12;
}
//adds '0' if there 1 digit.
if (string(thehours).length == 1) {
thehours="0"+thehours;
}
if (string(theminutes).length == 1) {
theminutes="0"+theminutes;
}
if (string(theseconds).length == 1) {
theseconds="0"+theseconds;
}
//displays time in dynamic text field.
thetime.text =thehours+":"+theminutes+":"+theseconds+" "+ampm;
}
var tl=this
createjs.ticker.addeventlistener('tick',showtime);
function showtime(event) {
//create new instance of date class.
var mytime = new date();
//this returns seconds, minutes , hour.
var theseconds=mytime.getseconds();
var theminutes=mytime.getminutes();
var thehours=mytime.gethours();
var ampm;
//displays am/pm depending on current hour.
if (thehours>=12) {
ampm="pm";
} else {
ampm="am";
}
//this subtracts 12 hour when greater 13.
if (thehours>=13) {
thehours=thehours-12;
}
if (thehours==0) {
thehours=thehours+12;
}
//adds '0' if there 1 digit.
if (string(thehours).length == 1) {
thehours="0"+thehours;
}
if (string(theminutes).length == 1) {
theminutes="0"+theminutes;
}
if (string(theseconds).length == 1) {
theseconds="0"+theseconds;
}
//displays time in dynamic text field.
tl.thetime.text =thehours+":"+theminutes+":"+theseconds+" "+ampm;
}
More discussions in Adobe Animate CC - General
adobe
Comments
Post a Comment