• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

TIMER CLOCK HELP NEEDED

Community Beginner ,
Apr 01, 2019 Apr 01, 2019

Copy link to clipboard

Copied

CAN THE CLOCK AND THE COUNTDOWN TIMER BE SET TO COUNT OFF SAME TIMER SO BEAT COUNT IS THE SAME I NEED THETIME AND COUNTDOWN TO MATCH SECOND FOR SECOND


import flash.utils.Timer; 
import flash.events.TimerEvent; 
 
var looper: Timer = new Timer(100);
timerTxt.text = ("05:00");
looper.start(); 
looper.addEventListener(TimerEvent.TIMER, loopF);

i--;


function loopF(event:TimerEvent):void{
var time: Date = new Date();

//time variables

var hours:* = time.getHours(); 
var minutes:* = time.getMinutes(); 
var seconds:* = time.getSeconds(); 
var hourStrg:String;  
var minuteStrg:String;
var secondStrg:String;

//date variables
  
var month: Number = time.getMonth() + 1; 
var day: Number = time.getDate(); 
var year: Number = time.getFullYear(); 
var monthStrg:String;  
var dayStrg:String;

   //date text
  
if (month < 10) { 
monthStrg = "0" + month + "/"; 
} else { 
monthStrg = month + "/"
}
if (day < 10) { 
dayStrg = "0" + day + "/"; 
} else { 
dayStrg = day + "/";
}
   //time text
  
if(String(seconds).length < 2){
seconds = "0" + seconds;
}
if(String(minutes).length < 2){
minutes = "0" + minutes;
}
if(hours > 11){
ampm_txt.text = "PM";
} else {
ampm_txt.text = "AM";
}
if(hours > 12){
hours = hours - 12;
}
if (String(hours).length < 2){
hours = "0" + hours;
}
time_txt.text = hours + ":" + minutes + ":" + seconds;
date_txt.text = monthStrg + dayStrg + year;
timerTxt.text = minutes + ":" + seconds
}

TOPICS
ActionScript

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 01, 2019 Apr 01, 2019

Copy link to clipboard

Copied

It can be done. In short, I have an ActionScript3 digital and analog clock running in parallel. I will post code, but at the moment I'm disabled. My computer with the Creative Cloud account to open Animate is unplugged, because I'm installing a Windows update which may take several hours on a second drive on the machine.

Note, my code might be slightly different to yours. I can't see from here. But the clocks play in sync.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 01, 2019 Apr 01, 2019

Copy link to clipboard

Copied

OK TY WHENEVER YOU CAN GET CHANCE TO POST I AM TRYING TO GET A CLOCK AND COUNTDOWN TIMER WORKING IN SYCH FOR PROJECT

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 01, 2019 Apr 01, 2019

Copy link to clipboard

Copied

Code for two clocks that run continuously.

To do a countdown instead of a clock, you need to set a zero-hour. A given number of seconds or milliseconds after the animation started, or an exact day and time, like April 4 at 16:00:00. If an exact time, you can use an online UTC calculator to return the UTC for April 4th, 16:00:00. Or use the formula for getting the number of milliseconds in ActionScript:

iDate = new Date();

Date.UTC(2019,04-1,04,16,0,0,0)-iDate.getTime();

The number of months is one less, because January is month 0. Milliseconds can be converted into a countdown format. Just subtract a second each tick.

// initiatize
var newsecond;
var newnewsecond;
var firstmoment;
var iDate;
var realmins;
var realsecs;
var newsecs;
var realmsecs;
var newhours;
var newminutes;
var formatdigits;
var seconds;
var newseconds;
var minutes;
var hours;
var checkdiff;

// in seconds
newsecond = 1;
// in milliseconds
newnewsecond = 1000;
// mc start
firstmoment = getTimer();
// Date object
iDate = new Date();
// 12-hour minutes since 12:00:00.000 AM
realmins = iDate.getHours()*60 + iDate.getMinutes();
// 12-hour seconds since 12:00:00.000 AM
realsecs = realmins*60 + iDate.getSeconds();
// 12-hour milliseconds since 12:00:00.000 AM
realmsecs = realsecs*1000 + iDate.getMilliseconds();
// new-seconds since 12:00:00.000 AM
newsecs = realmsecs * 1/1000;
// new-hours since 12:00:00.000 AM
newhours = newsecs / 3600;
// new-minutes since last new-hour
newminutes = newsecs%3600 / 60;
// new-seconds since last new-minute
newseconds = newsecs%3600%60 / 12*12;

// function
formatdigits = function() {
if (seconds>=60) {
  seconds = seconds - 60;
  minutes++;
  if (minutes>=60) {
   minutes =  minutes - 60;
   hours++;
  }
}
if (hours==0) {
  hours = 12;
}
if (hours>12) {
  hours = hours - 12;
}
if (seconds.toString().length==1) {
  seconds = "0" + seconds;
}
if (minutes.toString().length==1) {
  minutes = "0" + minutes;
}
if (hours.toString().length==1) {
  hours = "0" + hours;
}
// digital time
MovieClip(root).at.digital.led.text = hours + ":" + minutes + ":" + seconds;
}

// pre-set digital clock
seconds = Math.round(newseconds);
minutes = Math.floor(newminutes);
hours = Math.floor(newhours);
formatdigits();
// pre-set clock Hands and shadows
secondhand.rotation = seconds * 360/60;
secondhandshadow.rotation = secondhand.rotation;
minutehand.rotation = newminutes * 360/60;
minutehandshadow.rotation = minutehand.rotation;
hourhand.rotation =  newhours * 360/12;
hourhandshadow.rotation = hourhand.rotation;
// enter frame function
root.addEventListener(Event.ENTER_FRAME, ticking);
function ticking(e:Event):void {
// elapsed time
checkdiff = getTimer() - firstmoment;
// update the time every new-second
if (checkdiff - (Math.round(newnewsecond)) > 0) {
  // rotate clock Hands and shadows
  secondhand.rotation = secondhand.rotation + (360/60);
  secondhandshadow.rotation = secondhand.rotation;
  minutehand.rotation = minutehand.rotation + (0.1);
  minutehandshadow.rotation = minutehand.rotation;
  hourhand.rotation = hourhand.rotation + (360/60) / 720;
  hourhandshadow.rotation = hourhand.rotation;
  // increment digital values
  seconds++;
  formatdigits();
  // new-second counter
  newnewsecond = newnewsecond + newsecond*1000;
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2019 Apr 22, 2019

Copy link to clipboard

Copied

this I code you sent

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

any ideas on making this work as real time timer

import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.ui.Mouse;
var myTimer:Timer = new Timer(1000, 300);
var i:Number = 300;
   // constructor code
timerTxt.text = String("05:00");
myTimer.addEventListener(TimerEvent.TIMER, updateTime);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);
startbutton.addEventListener(MouseEvent.CLICK, StartNow);
pausebutton.addEventListener(MouseEvent.CLICK, PauseNow);
restartbutton.addEventListener(MouseEvent.CLICK, restartNow);
function updateTime(e:TimerEvent){
i--;
var totalSeconds:* = i;
var minutes:* = Math.floor(totalSeconds/60);
var seconds:* = totalSeconds % 60;
if(String(minutes).length < 2)
minutes = "0" + minutes;
if(String(seconds).length < 2)
seconds = "0" + seconds;
timerTxt.text = minutes + ":" + seconds;
  }
function TimerComplete(e:TimerEvent){
messageTxt.text = "PRESENTATION IS NOW OVER"
timerTxt.text = String("00:00");
}
function StartNow(e:MouseEvent){
myTimer.start();
}
function PauseNow(e:MouseEvent){
myTimer.stop();
}
function restartNow(e: MouseEvent): void 

myTimer.stop(); 
myTimer = new Timer(1000); 
myTimer.addEventListener(TimerEvent.TIMER, updateTime); 
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete); 
i =300;
messageTxt.text = "" 
timerTxt.text = String("05:00"); 
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2019 Apr 23, 2019

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines