TheTAZZone - Internet Chaos

Tutorial – Displaying Date/Time in Flash MX

ORIGINALLY POSTED BY NOKIA FOR THETAZZONE/TAZFORUM HERE

Do not use, republish, in whole or in part, without the consent of the Author. TheTAZZone policy is that Authors retain the rights to the work they submit and/or post…we do not sell, publish, transmit, or have the right to give permission for such…TheTAZZone merely retains the right to use, retain, and publish submitted work within it’s Network

[code]Valhallen had very kindly allowed us to host his tutorial on The TAZ.

Enjoy!
[/code]

Ok now this is not the easiest way of doing this in Flash Mx but it does use the new switch function so thought would let everyone see it
original tut is at -> [url]http://www.actionscript.org/tutoria…ime/index.shtml[/url]

thought I would rewrite it to make it a bit easier to understand and also add some extra functionality to it……

ok so lets start your new movie ::::

first create a new movieclip called date_mc – this will hold your actual display so in it create a dynamic text box called date_txt

set the proporties (text font/color etc) and then name it as date_txt – this is done in the proporties menu were it says var

ok now still in your date_mc create a new keyframe on frame 2 – change the date_txt’s name in this frame (not first one) to date_txt2

ok now drag an instance of this movieclip onto the main timeline – give it an instance name of date_mc

ok almost done now just to make our button – create a new layer above the one holding date_mc and use the fill rectangle tool to draw a large rectangle covering your date_mc – set line to off and pick any color you wish – doesn’t matter wont be seen.

Now select the rectangle and convert it to a button (press F8 in windows) called date_btn – now set its instance name to the same (date_btn) and then change its alpha (in proporties menu) to 0% so is invisible

ok now for the code ::::

in the date_mc movieclip insert a stop action on frame 1 like so

[code]stop(); [/code]

and then on your main timeline create a new layer called actions and insert this code :::

code:——————————————————————————–[code]function howlong(arg) {
if (length(arg)==1) {
arg = “0” + arg;
return arg;
}
else {
arg = arg;
return arg;
}
}
myDate = new Date();

hr = howlong(String(myDate.getHours()));
mnt = howlong(String(myDate.getMinutes()));

daytext = myDate.getDay();
dd = myDate.getDate();
mm = myDate.getMonth();
yyyy = myDate.getFullYear();

switch (daytext) {
case 0: daytext = “Sunday”;
break;
case 1: daytext = “Monday”;
break;
case 2: daytext = “Tuesday”;
break;
case 3: daytext = “Wednesday”;
break;
case 4: daytext = “Thursday”;
break
case 5: daytext = “Friday”;
break;
case 6: daytext = “Saturday”;
break
}

switch (mm) {
case 0: mm = “January”;
break;
case 1: mm = “February”;
break;
case 2: mm = “March”;
break;
case 3: mm = “April”;
break;
case 4: mm = “May”;
break
case 5: mm = “June”;
break;
case 6: mm = “July”;
break
case 7: mm = “August”;
break
case 8: mm = “September”;
break
case 9: mm = “October”;
break
case 10: mm = “November”;
break
case 11: mm = “December”;
break
}

_root.date_mc.date_txt = (hr + “:” + mnt)
_root.date_mc.date_txt2 = (daytext + “,” + dd + ” ” + mm + ” ” + yyyy)

date_btn.onRollOver = function(){
_root.date_mc.gotoAndStop(2);
}
date_btn.onRollOut = function(){
_root.date_mc.gotoAndStop(1);
}
[/code]

ok the code is pretty much self explanitary – and is explained here -> [url]http://www.actionscript.org/tutoria…ime/index.shtml[/url]

but i will go over the changes i made ::: the last part

[code]_root.date_mc.date_txt = (hr + “:” + mnt)
_root.date_mc.date_txt2 = (daytext + “,” + dd + ” ” + mm + ” ” + yyyy)

date_btn.onRollOver = function(){
_root.date_mc.gotoAndStop(2);
}
date_btn.onRollOut = function(){
_root.date_mc.gotoAndStop(1);
}
[/code]

as you can see the original tut just had a static display showing date/time – now i have altered it so that time is displayed until you mouseover and then it switches to date – this is easily done

the first 2 lines assign the values to the 2 different txt fields
then the button actions tell it which frame in date_mc to look at – now because the different txt fields are on different frames only one is visible either date/time

could also have been done using visible = false;

eg ::::

code:——————————————————————————–[code]date_btn.onRollOver = function(){
date_txt._visible = false;
date_txt2._visible = true;
}
[/code]

but i like to keep everything neatly in its own movieclips

v_Ln

Leave a Reply

Your email address will not be published. Required fields are marked *

Advertise

If you'd like to advertise on The Mutt ( aka TheTAZZone.com ) feel free to contact us at: administration[at]thetazzone.com

TheTAZZone is a non-commercial entity. We do not sell any products or services ourselves. Our revenue comes from advertising and donations only.

We appreciate your support! Your advertising revenue ( or donations ) helps us to continue to upgrade, improve, and offset the costs of maintaining this site.

Donations can be made through the page ' Donate '.