AS3简单数字时钟
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3简单数字时钟相关的知识,希望对你有一定的参考价值。
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).
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; }
以上是关于AS3简单数字时钟的主要内容,如果未能解决你的问题,请参考以下文章