1 ImportFlash.utils.Timer;2 Importflash.events.TimerEvent;3 ImportFlash.text.TextField;4 5 varText:textfield =NewTextField ();6 varEndtime:date =NewDate (2015,7-1,29,15,30,0);7 varTimer:timer =NewTimer (1000);8Text.autosize ="left";9 This. AddChild (text);Ten Timer.addeventlistener (timerevent.timer,ontimer); One Timer.start (); A functionOnTimer (e:timerevent):void - { -Text.text = Formatecountdown (EndTime,NewDate ()); the } - functionFormatecountdown (endtime:date,nowtime:date): String - { - varTotal Number= Math.floor ((Endtime.gettime ()-nowtime.gettime ())/1000); + if(Total > 0) { - varDay Number= Math.floor (total/86400); +Total = Total-day * 60 * 60 * 24; A varHours Number= Math.floor (total/3600); atTotal = total-hours * 60 * 60; - varMinutes Number= Math.floor (total/60); -Total = Total-minutes * 60; - varSeconds Number=Total ; - returnDay.tostring () +"Day"+hours.tostring () +"When"+minutes.tostring () +"Min"+seconds.tostring () +"Seconds"; - } in return "The countdown date is over ..."; -}
[ActionScript 3.0] Simple countdown