Copy link to clipboard
Copied
I want to create a swf file which displays date in the format Tuesday, July 25, 2017 and updates it with current time
please suggest me a solution.
AS3 supports a more direct method for doing this sort of thing.
function updateDate(evt:TimerEvent):void {
var d:Date = new Date();
var df:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT);
df.setDateTimePattern("EEEE, MMMM d, yyyy");
var fd:String = df.format(d);
trace(fd);
}
DateTimeFormatter - Adobe ActionScript® 3 (AS3 ) API Reference
As for automatic updating, while you could schedule a timer to fire every 24 hours, the probability of timer drift is high. The function i
...Copy link to clipboard
Copied
var d:Date;
var dowA:Array=['Sunday','Monday',etc];
var moyA:Array=['January','February',etc];
var t:Timer=new Timer(1000,0;
t.addEventListener(TimerEvent.TIMER,f);
t.start();
function f(e:TimerEvent):void{
d=new Date();
tf.text = formatF(d);
}
function formatF(d:Date):String{
return dowA[d.day]+', '+moyA[d.month]+', '+d.fullYear;
}
Copy link to clipboard
Copied
AS3 supports a more direct method for doing this sort of thing.
function updateDate(evt:TimerEvent):void {
var d:Date = new Date();
var df:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT);
df.setDateTimePattern("EEEE, MMMM d, yyyy");
var fd:String = df.format(d);
trace(fd);
}
DateTimeFormatter - Adobe ActionScript® 3 (AS3 ) API Reference
As for automatic updating, while you could schedule a timer to fire every 24 hours, the probability of timer drift is high. The function itself is so trivial that there would be no harm in calling it once a minute (every 60,000 milliseconds). So something like...
var myTimer:Timer = new Timer(60000);
myTimer.addEventListener(TimerEvent.TIMER, updateDate);
myTimer.start();