/ Published in: ActionScript 3
This example expects there to be a dynamic textfield on the stage with the instance name of 'myTextFieldOnStage'. Remember to embed the fonts (Numerals and Colon).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import flash.text.TextField; var timeTextfield:TextField = myTextFieldOnStage; timeTextfield.text = getFormattedTime(); var clockTimer:Timer = new Timer(1000, 0); clockTimer.addEventListener(TimerEvent.TIMER, onClockTimer); clockTimer.start(); function onClockTimer(e:TimerEvent):void { timeTextfield.text = getFormattedTime(); } function getFormattedTime():String { var now:Date = new Date(); var hrs:String = String(now.getHours()); if (hrs.length < 2) { hrs = "0" + hrs; } var mins:String = String(now.getMinutes()); if (mins.length < 2) { mins = "0" + mins; } return hrs + ":" + mins; }