Timer的一個應用例子--一個簡單的表

某日閒來無事花幾分鐘整的,就是一個Timer定時器的應用.

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="absolute" fontSize="12">
    <mx:Script>
        <![CDATA[
        import mx.formatters.DateFormatter;
        import mx.controls.Alert;
        import flash.utils.Timer;
        private var today:Date;
        [Bindable]
        private var timestr:String;
            function init():void{
                var timer:Timer = new Timer(1000);
                timer.addEventListener(TimerEvent.TIMER,change);
                timer.start();
            }
            function change(e:TimerEvent):void{
                // 格式化函數
                var myDateFormatter:DateFormatter=new DateFormatter();
                // 定義日期格式
                myDateFormatter.formatString="YYYY-MM-DD JJ:NN:SS";
                today = new Date();
                timestr = myDateFormatter.format(today);
            }
        ]]>
    </mx:Script>
    <mx:Panel x="226" y="61" width="250" height="200" layout="absolute">
        <mx:Text x="10" y="10" text="{timestr}" fontFamily="Courier New"/>
    </mx:Panel>
</mx:Application>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章