PDA

View Full Version : Digital Clock


Duece
01-15-2003, 03:32 PM
Ok, I've done all the tutorials and lessons in MX but being a complete newb to coding I can't figure this out. I've drawn out a digital clock and distributed each of the lines that would make up the numbers to a seperate layer then named them and placed them in seperate folders for each digit. I also have AM and PM LED lights on the clock, I'm using the AM light to test my coding so far and have been unsuccesful each time I've tried. I know getHours returns a value from 00-23, so I've tried to code it so if the value is > 12 the _visible = false. I'm not sure if I'm messing up on the syntax or completely missing the some important steps. A spoiler on exactly how to code this object would be super.

What about the numbers? Each number is comprised of 7 bar style lights that will be toggled on or off in varying combinations to make up each number. I'm assuming I would change each line into a symbol then edit it's actions to get the time then figure out if the current time required that particular light to be lit. Anyone have any suggestions on syntax for these?

Duece
01-15-2003, 04:07 PM
My current code is as follows:

myDate = "new Date";
if (myDate.getHours > 11) {
_root.am_dot._visible=false
}
if (myDate.getHours < 12) {
_root.pm_dot._visible=false
}

tg
01-15-2003, 04:20 PM
look in both the library section and the movie section of this site. lots of clocks have been posted in these locations, and you will probably find your answer there. if not come back here and do a search for 'clock', and you'll find even more source code.

tg
01-15-2003, 04:23 PM
sorry forgot...

for your am pm thing try:

myDate = new Date();//no quote around new date and dont forget the ().
if (myDate.getHours() > 11) {
_root.am_dot._visible=false;
_root.pm_dot._visible=true;
} else{
_root.pm_dot._visible=false;
_root.am_dot._visible=true;
}

Duece
01-15-2003, 05:29 PM
Thanks much tg, the AM/PM dot thing worked like a champ, here's what I'm going with so far for the hours. . .

if (myDate.getHours=00,12) {
_root.hour1_bottom._visible=true
_root.hour1_top._visible=true
_root.hour2_topmid._visible=true
_root.hour2_mid._visible=true
_root.hour2_btmmid._visible=true
_root.hour2_lefttop._visible=false
_root.hour2_leftbtm._visible=true
_root.hour2_rightbtm._visible=false
_root.hour2_righttop._visible=true
}

that over and over swapping out 00,12 for 01,13 and 02, 14 etc. and then switching the _visible parameter for the corresponding "lights", seems to be working great so far, thanks so much for all the help again )

Duece
01-15-2003, 06:05 PM
OK nevermind that's not working either, I got rid of the dual numbers and just did a set for each possible hour, 00-23. This worked until I got to 08, then it finds a syntax error, but the syntax is EXACTLY the same as the other sets, 00-07, I'm hella confused. Here's a copy of the first 9 sets of code and the error I get for the 08 set of code

if (myDate.getHours=00) {
_root.hour1_bottom._visible=true
_root.hour1_top._visible=true
_root.hour2_topmid._visible=true
_root.hour2_mid._visible=true
_root.hour2_btmmid._visible=true
_root.hour2_lefttop._visible=false
_root.hour2_leftbtm._visible=true
_root.hour2_rightbtm._visible=false
_root.hour2_righttop._visible=true
}
else if (myDate.getHours=01) {
_root.hour1_bottom._visible=false
_root.hour1_top._visible=false
_root.hour2_topmid._visible=false
_root.hour2_mid._visible=false
_root.hour2_btmmid._visible=false
_root.hour2_lefttop._visible=false
_root.hour2_leftbtm._visible=false
_root.hour2_rightbtm._visible=true
_root.hour2_righttop._visible=true
}
else if (myDate.getHours=02) {
_root.hour1_bottom._visible=false
_root.hour1_top._visible=false
_root.hour2_topmid._visible=true
_root.hour2_mid._visible=true
_root.hour2_btmmid._visible=true
_root.hour2_lefttop._visible=false
_root.hour2_leftbtm._visible=true
_root.hour2_rightbtm._visible=false
_root.hour2_righttop._visible=true
}
else if (myDate.getHours=03) {
_root.hour1_bottom._visible=false
_root.hour1_top._visible=false
_root.hour2_topmid._visible=true
_root.hour2_mid._visible=true
_root.hour2_btmmid._visible=true
_root.hour2_lefttop._visible=false
_root.hour2_leftbtm._visible=false
_root.hour2_rightbtm._visible=true
_root.hour2_righttop._visible=true
}
else if (myDate.getHours=04) {
_root.hour1_bottom._visible=false
_root.hour1_top._visible=false
_root.hour2_topmid._visible=false
_root.hour2_mid._visible=true
_root.hour2_btmmid._visible=false
_root.hour2_lefttop._visible=true
_root.hour2_leftbtm._visible=false
_root.hour2_rightbtm._visible=true
_root.hour2_righttop._visible=true
}
else if (myDate.getHours=05) {
_root.hour1_bottom._visible=false
_root.hour1_top._visible=false
_root.hour2_topmid._visible=true
_root.hour2_mid._visible=true
_root.hour2_btmmid._visible=true
_root.hour2_lefttop._visible=true
_root.hour2_leftbtm._visible=false
_root.hour2_rightbtm._visible=true
_root.hour2_righttop._visible=false
}
else if (myDate.getHours=06) {
_root.hour1_bottom._visible=false
_root.hour1_top._visible=false
_root.hour2_topmid._visible=true
_root.hour2_mid._visible=true
_root.hour2_btmmid._visible=true
_root.hour2_lefttop._visible=true
_root.hour2_leftbtm._visible=true
_root.hour2_rightbtm._visible=true
_root.hour2_righttop._visible=false
}
else if (myDate.getHours=07) {
_root.hour1_bottom._visible=false
_root.hour1_top._visible=false
_root.hour2_topmid._visible=true
_root.hour2_mid._visible=false
_root.hour2_btmmid._visible=false
_root.hour2_lefttop._visible=false
_root.hour2_leftbtm._visible=false
_root.hour2_rightbtm._visible=true
_root.hour2_righttop._visible=true
}
else if (myDate.getHours=08) {
_root.hour1_bottom._visible=false
_root.hour1_top._visible=false
_root.hour2_topmid._visible=true
_root.hour2_mid._visible=true
_root.hour2_btmmid._visible=true
_root.hour2_lefttop._visible=true
_root.hour2_leftbtm._visible=true
_root.hour2_rightbtm._visible=true
_root.hour2_righttop._visible=true
}

and the error:
Scene=Scene 1, Layer=Actions, Frame=1: Line 97: ')' expected
else if (myDate.getHours=08) {

tg
01-15-2003, 07:47 PM
not too sure whats up.
2 things i did notice:
1. change:
myDate.getHours
to:
myDate.getHours()
2. use a semi-colon (';') at the end of your statements.
altho, flash will let you by without them, its good programming pactice, and will probably alow flash to run alittle more efficiently, cause it tells flash specifically when the end of the statement is occuring. (not sure about that second one hehheh... just blowing smoke).

Duece
01-15-2003, 08:13 PM
done and done tg, it seems anytime I enter either 08 or 09 I get the same error, the syntax is character for character the same as the other entries, must be something with 08 and 09 I suppose, can I put the 08 and 09 in quotes so it doesn't mis-interpret it? (which I think it's doing) Going to try that now. . .

tg
01-15-2003, 08:40 PM
o crap... i hate it when i do that.


i just noticed a big problem. it may not solve your problem, but you need to change all of your '=' to '==' a single = sign assign a value, a double == sign compares 2 values.... it will definitly change the way you code executes.

Duece
01-15-2003, 10:09 PM
Ok, I got all the ='s changed to =='s that fixxed an alternate problem I was having, but the 08 and 09 thing still messes the script up. I replaced 08 and 09 with just 8 and 9 and finished up the coding and I'm now the proud owner of a neat little digital clock. I'm not sure why it had a problem with 08 and 09 but it's working now, I'll post the file when I get home tonight if anyone would like to see it in action. Thanks for all the help tg!

Duece
01-16-2003, 04:41 AM
Ok here's the links

fla: http://68.112.133.42/digital clock finished.fla

swf: http://68.112.133.42/digital clock finished.swf