00:00
00:00
Newgrounds Background Image Theme

Troggie just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Real-time Clock Tutorial

13,446 Views | 71 Replies
New Topic Respond to this Topic

Real-time Clock Tutorial 2005-06-21 10:39:37


<-------------------------------------------------------------->
This tutorial is very simple, any beginner flash artist can do it.
<-------------------------------------------------------------->

<-->
STEP 1
<-->
Make a symbol, and inside it, make 3 movie clips. One for the second hand, one for the minute hand, and one for the hour hand. Give the second hand an instance name of "sHand", the minute hand an instance name of "mHand", and the hour hand an instance name of "hHand". Make sure that they are centered, and that the registration point of the hands is where you want them to rotate about.

<-->
STEP 2
<-->
Place the following code in your clock symbol.:

|-----|
CODE
|-----|

onClipEvent (enterFrame) {
var my_date:Date = new Date();
hours = my_date.getHours();
minutes = my_date.getMinutes();
seconds = my_date.getSeconds();
hHand._rotation = (1/(12/(hours+minutes/60)))*360;
mHand._rotation = (1/(60/minutes))*360;
sHand._rotation = (1/(60/seconds))*360;
}

<-->
STEP 3
<-->
Edit your graphics to whatever you want them to be. You can make as many clocks as you want.
Advanced AS'ers, you can even edit the script to make a 24 hour clock or whatever you want!

<-------------------------------------------------------------->
Example Time!
<-------------------------------------------------------------->
http://img192.echo.cx/my.php?image=clock1pz.swf

<-------------------------------------------------------------->

Post your best clocks!

<-------------------------------------------------------------->
This has been a Glaiel Gamer tutorial.

Response to Real-time Clock Tutorial 2005-06-21 10:52:27


What about digital clocks?


BBS Signature

Response to Real-time Clock Tutorial 2005-06-21 10:59:28


Here is my horrendous creation!

N00B Clock

Enjoy it.

Response to Real-time Clock Tutorial 2005-06-21 11:00:11


Digital clocka are even easier, you just need 3 dynamic text boxes, 1 for "seconds", 1 for "minutes" and 1 for "hours"

or, here's a code for you.

onClipEvent (enterFrame) {
var my_date:Date = new Date();
hours = my_date.getHours()+1;
minutes = my_date.getMinutes()+1;
seconds = my_date.getSeconds()+1;
if(hours>12){
hours -= 12
}

disp = hours+":"+minutes+":"+seconds
}

*Remove the bold part for a 24 hour clock

Now, all you need is a dynamic text box in the clock symbol, and set the "variable" part to "disp".

Response to Real-time Clock Tutorial 2005-06-21 11:01:23


At 6/21/05 10:59 AM, -KJDunwoody- wrote: Cool.
How did you come up with that?

I wish i could have.

My next game has unlockable "toys" and I decided to put a clock as one. So I did a tiny bit of work and came up with this.

Response to Real-time Clock Tutorial 2005-06-21 11:05:41


Here's a better code for a digital clock, mistake in the first one.
onClipEvent (enterFrame) {
var my_date:Date = new Date();
hours = my_date.getHours();
minutes = my_date.getMinutes();
seconds = my_date.getSeconds();
if (hours>12) {
hours -= 12;
}
if (seconds<10) {
seconds = "0"+seconds;
}
if (minutes<10) {
minutes = "0"+minutes;
}
if (hours<10) {
hours = "0"+hours;
}
disp = hours+":"+minutes+":"+seconds;
}

Response to Real-time Clock Tutorial 2005-06-21 11:20:10


I have AIM, KingGoboWoboFaun
glaielgamesmail@comcast.net

Response to Real-time Clock Tutorial 2005-06-21 11:21:05


At 6/21/05 11:01 AM, Glaiel_Gamer wrote: My next game has unlockable "toys" and I decided to put a clock as one. So I did a tiny bit of work and came up with this.

Last time I saw that, it was looking good. Hows it coming along?


Sup, bitches :)

BBS Signature

Response to Real-time Clock Tutorial 2005-06-21 11:26:05


OH CRAP I FORGOT TO MENTION SOMETHING!
IN your hand symbols MAKE SURE THAT THEY ARE POINTING AT THE 12!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!
(This is my rarely-used alt account)

DEADSiM2, I have 5/13 games and 8/20 toys completed.

Response to Real-time Clock Tutorial 2005-06-21 11:30:54


Isn't it forbidden to have an alt account?


BBS Signature

Response to Real-time Clock Tutorial 2005-06-21 11:36:17


You know there's a clock in the samples?

Response to Real-time Clock Tutorial 2005-06-21 11:38:39


At 6/21/05 11:30 AM, Dark_Toaster wrote: Isn't it forbidden to have an alt account?

No, just to use the alt account to get around bans.


Sup, bitches :)

BBS Signature

Response to Real-time Clock Tutorial 2005-06-21 14:00:52


At 6/21/05 11:36 AM, JafitMan wrote: You know there's a clock in the samples?

I don't care.

Response to Real-time Clock Tutorial 2005-06-21 22:55:29


That post needed to be posted, though. It was VERY important.

Response to Real-time Clock Tutorial 2005-06-27 15:45:26


At 6/21/05 10:39 AM, Glaiel_Gamer wrote: <-------------------------------------------------------------->
This has been a Glaiel Gamer tutorial.

lol. This looks VERY similar to a dial clock AS snippet I created and posted a little while ago, even down to the Instance Names... nvm, it's all good =)


- - Flash - Music - Images - -

BBS Signature

Response to Real-time Clock Tutorial 2005-06-28 14:18:40


really? Hmm... I never saw that topic.....

Response to Real-time Clock Tutorial 2005-06-28 15:31:11


riiiight, :p jp

Response to Real-time Clock Tutorial 2005-06-28 15:35:33


At 6/28/05 02:18 PM, Glaiel_Gamer wrote: really? Hmm... I never saw that topic.....

Just checked, it's not quite the same. I made it for AngelClock quite a while ago, didn't realise there was one in the Flash sample files...

http://www.newgrounds.com/bbs/topic.php?id=284910


- - Flash - Music - Images - -

BBS Signature

Response to Real-time Clock Tutorial 2005-06-28 15:37:50


ok. I didn't realize there was one in there either. Oh well.

Response to Real-time Clock Tutorial 2005-06-28 15:38:55


Yay, now we all are friends again! Lets look for treasure!

Response to Real-time Clock Tutorial 2005-06-28 15:42:23


At 6/28/05 03:38 PM, speddyfeddy1234 wrote: Yay, now we all are friends again! Lets look for treasure!

Inglor.onReadJackshit=func(content);

function func(content):Punch{
if(Content.Spamness>5){
content.Spamness--;
func(content);
return Punch;
}
}

this is what you get, 8 punches, if you know what this means, I'll take that back :P

Response to Real-time Clock Tutorial 2005-06-28 15:51:20


No, no, no, you got it all wrong...

Denvish.onReadJackshit=func(content);

function func(content):Ban{
if(content.Spamness>5){
content.Spamness--;
func(content);
return Ban;
}
}

lol@stealing code


- - Flash - Music - Images - -

BBS Signature

Response to Real-time Clock Tutorial 2005-06-28 15:57:45


nice stealing :)

but got it wrong , you just banned him alot of times (recursion tutorial coming soon)

Denvish.onReadJackshit=func(content.Spamness);

function func(content):Number{
Spamness=Spamness*(Spamness>12)+7*(Spamness>12);
if(Spamness>5){
return Spamness+func(Spamness-1);
}
return 0;
}

This actually bans him for a day for each Spamness >5 and maxs at 7 days

I love recursive stuff :)

Response to Real-time Clock Tutorial 2005-06-28 15:58:54


Or

GG.onReadJackshit=func(content);

function func(content):nothing{
if(content.Spamness>5){
content.Spamness--;
func(content);
return nothing; // I have no mod powers
}
}

Response to Real-time Clock Tutorial 2005-06-28 16:01:54


At 6/28/05 03:57 PM, Inglor wrote: nice stealing :)

but got it wrong , you just banned him alot of times (recursion tutorial coming soon)

Denvish.onReadJackshit=func(content.Spamness);

function func(content):Number{
Spamness=Spamness*(Spamness>12)+7*(Spamness>12);
if(Spamness>5){
return Spamness+func(Spamness-1);
}
return 0;
}

This actually bans him for a day for each Spamness >5 and maxs at 7 days

I love recursive stuff :)

If you love recursion so much, try this

function hurt(username){
username.punch
if(modpower){
username.ban
}
hurt(username)
}
hurt("speddyfeddy1234")

Response to Real-time Clock Tutorial 2005-06-28 16:02:42


oops, I made a baddy :P

Denvish.onReadJackshit=Ban(content);

function Ban(content):BanType{
return "You have been banned for" + func(content.Spamness) + "Days, Reason:"+content;
}
function func(Spamness):Number{
Spamness=Spamness*(Spamness>12)+7*(Spamness>12);
if(Spamness>5){
return Spamness+func(Spamness-1);
}
return 0;
}

Response to Real-time Clock Tutorial 2005-06-28 16:04:14


GG didn't get the recursive function calling either, but oh well ;) like i said, tutorial coming soon ;)

Response to Real-time Clock Tutorial 2005-06-28 16:05:41


I called the function from the function, wouldn't that be recursive?

Response to Real-time Clock Tutorial 2005-06-28 16:58:50


Nice job, Glaiel, lol. I like yours, Flea PWNZORZ!

Response to Real-time Clock Tutorial 2005-07-21 06:28:35


Aggh! Either digital or analogical clock don't work with me... help me.


I'm built from the leftover parts.