# Clock?

**URL:** <https://forum.kirupa.com/t/clock/3686>\
**Category:** programming\
**Created:** [October 22, 2001, 12:33am UTC](https://forum.kirupa.com/t/clock/3686 "2001-10-22T00:33:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 22, 2001, 12:33am UTC](https://forum.kirupa.com/t/clock/3686/1 "2001-10-22T00:33:04Z")

</div>

Is there a way to make a circular clock in flash? With the minute and hour and second hands? B/c I can make one in java…but not sure if it can be done in Flash or not. If so, I think it’d also make a great tutorial of some sort.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 22, 2001, 3:39am UTC](https://forum.kirupa.com/t/clock/3686/2 "2001-10-22T03:39:02Z")

</div>

it can be done. i saw a tutorial on it on flashkit…a long long time ago.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 22, 2001, 4:59am UTC](https://forum.kirupa.com/t/clock/3686/3 "2001-10-22T04:59:59Z")

</div>

- edited to add “sweeping” to the second hand\*
- edited again to add “sweeping” to the other hands\*

not as hard as you might think.

here’s what i did playing around with thoripes answer on the other board (er, the actionscript board):

```auto
   
onClipEvent(enterFrame){
&nbsp &nbsp &nbsp &nbsp myDate = new Date();
&nbsp &nbsp &nbsp &nbsp hours = myDate.getHours();
&nbsp &nbsp &nbsp &nbsp if(hours>12){hours-=12;ampm="pm";}
&nbsp &nbsp &nbsp &nbsp else{if(hours==0){hours=12;}ampm="am";}
&nbsp &nbsp &nbsp &nbsp min = myDate.getMinutes();
&nbsp &nbsp &nbsp &nbsp seconds = myDate.getSeconds();
&nbsp &nbsp &nbsp &nbsp ms = myDate.getMilliseconds();
&nbsp &nbsp &nbsp &nbsp if(seconds<10){seconds = "0" + seconds;}
&nbsp &nbsp &nbsp &nbsp hourhand._rotation = hours*30 + min/2;
&nbsp &nbsp &nbsp &nbsp minutehand._rotation = min*6 + seconds/10;
&nbsp &nbsp &nbsp &nbsp secondhand._rotation = seconds*6 + ms*(6/1000);
&nbsp &nbsp &nbsp &nbsp if(ms<100){if(ms<10){ms="00"+ms;}else{ms="0"+ms;}}
&nbsp &nbsp &nbsp &nbsp now = hours+":"+min+":"+seconds+"."+ms+" "+ampm;
&nbsp &nbsp &nbsp &nbsp if(ms.length>3){trace(ms);}
}

```

you need to create movies for the hands, they’re referred to as hourhand, minutehand, and (wait for it…) secondhand. ; )

they should be aligned bottom in their movies to make the rotation work as expected, if you play with it you’ll see what i mean. and, of course, everything needs to go into whatever movie you put the code in.

the “now” variable is superfluous to the clock, as is “ampm”, i just never bothered to cull them from my prev example.

cheers.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 22, 2001, 8:31pm UTC](https://forum.kirupa.com/t/clock/3686/4 "2001-10-22T20:31:13Z")

</div>

in ya first key frame ya have the following actions:

attachMovie(“clockFace”, “clockFace”, 0);  
attachMovie(“hand”, “secondHand”, 3);  
attachMovie(“hand”, “minuteHand”, 2);  
attachMovie(“hand”, “hourHand”, 1);  
clockFace.\_x = 275;  
clockFace.\_y = 200;  
clockFace.\_height = 150;  
clockFace.\_width = 150;  
secondHand.\_X = clockFace.\_x;  
secondHand.\_y = clockFace.\_y;  
secondHand.\_height = clockFace.\_height / 2.2;  
secondHandColor = new Color(secondHand);  
secondHandColor.setRGB(0xFFFFFF);  
minuteHand.\_x = clockFace.\_x;  
minuteHand.\_y = clockFace.\_y;  
minuteHand.\_height = clockFace.\_height / 2.5;  
hourHand.\_x = clockFace.\_x;  
hourHand.\_y = clockFace.\_y;  
hourHand.\_height = clockFace.\_height / 3.5;  
function updateClock () {  
var now = new Date();  
var dayPercent = (now.getHours() % 12) / 12;  
var hourPercent = now.getMinutes() / 60;  
var minutePercent = now.getSeconds() / 60;  
hourHand.\_rotation = 360 \* dayPercent + hourPercent \* (360 / 12);  
minuteHand.\_rotation = 360 \* hourPercent;  
secondHand.\_rotation = 360 \* minutePercent;  
}

in the second key frame you have:

updateClock();

then in the thrid you have:

gotoAndPlay(2);

then all you need is your clock face and your hour hand and second hand.

i dunno if im talking sh!t here so people that actually understand maybe will tell me if i am.

p.s  
cheers kirupa 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 23, 2001, 2:45am UTC](https://forum.kirupa.com/t/clock/3686/5 "2001-10-23T02:45:47Z")

</div>

nice stuff there fellows.
