Skip to main content
Participant
September 12, 2017
Answered

creating time and date .swf file

  • September 12, 2017
  • 1 reply
  • 2223 views

I've tried looking for several resources but have not found any that cover the entire process.

I'm new to Animate and need to create a simple .swf file that displays the written date (Tuesday, Sept. 12) and the time in 12 hr format with AM/PM.

Would someone be able to walk me through the process?

Thank you!

This topic has been closed for replies.
Correct answer Colin Holgate

thanks again for your help, it doesnt seem to be working for me.

for your initial post when using:

var days:Array = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

var months:Array = ["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."];

var ampm:String = "AM";

var d:Date = new Date();

var day:int = d.day;

var date:int = d.date;

var hour:int = d.hours;

var min:int = d.minutes;

var month:int = d.month;

if(hour>12){

  hour = hour - 12;

  ampm = "PM";

}

if(hour==0) hour = 12;

trace(days[day]+", " + months[month] + " " + date);

How was the document set up? Did you have to include any text? Where you working with only one frame?

Sorry for all of the questions, but getting a bit lost in trying to code this. Very much appreciate the help!


Here is a working version of the one that is two frames, and that puts the date into a field:

showdate

Here's the FLA that made that:

http://colin.scienceninja.com/showdate.fla.zip

If you see a message that says that the file was made with a later version, don't worry about it. I'm often a little ahead of everyone else! It should work ok.

1 reply

Colin Holgate
Inspiring
September 12, 2017

I don't think there is a simple one function way to do it, but you can get what you need in this sort of way (I tested it and it seems to work):

var days:Array = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

var months:Array = ["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."];

var ampm:String = "AM";

var d:Date = new Date();

var day:int = d.day;

var date:int = d.date;

var hour:int = d.hours;

var min:int = d.minutes;

var month:int = d.month;

if(hour>12){

  hour = hour - 12;

  ampm = "PM";

}

if(hour==0) hour = 12;

trace(days[day]+", " + months[month] + " " + date);

Participant
September 12, 2017

thanks for your quick response Colin.

Truly being a newbie to Animate, not very confident knowing how to get it started.

Should I do two different dynamic text fields and add the code on the properties?

If so, what should I name the text?

Colin Holgate
Inspiring
September 12, 2017

You could take things in stages. If you want this to update all the time the easiest way would be to have two frames, with the script I gave in a keyframe in frame 1, and this in a keyframe in frame 2:

gotoAndPlay(1);

That would then loop around forever, and as the date changes the text would update.

If you had one textfield you could have a line line this (instead of the trace command):

resultsText.text = days[day]+", " + months[month] + " " + date;

'resultsText' would be a dynamic textfield that was across frames 1 and 2, and in Properties you gave the textfield a name of resultsText.

It would be possible to have several fields for the different parts, but you would run into problems with getting the spacing correct.

See if you can get one field working.