Home > AS3 > Current System Time using Timer()

Current System Time using Timer()

This is about basically how to get your current system time using Timer() function using AS3.

 

For this you need to create four dynamic text boxes and name those as txtHrstxtMinstxtSecs, and txtDate.

 

Put the following actions in your movie frame and create a class and use these.

 

var time:Timer = new Timer(10);

tm.addEventListener(TimerEvent.TIMER, update);

function update(tevt:TimerEvent):void {

                         var now:Date = new Date();

                         var hr:Number = now.hours;

                         var min:Number = now.minutes;

                         var sec:Number = now.seconds;

                         if (hr > 12) {

                                                  hr -= 12;

                         }

                         txtHrs.text = String(hr);

                         if (min < 10) {

                                                  txtMins.text = “0″;

                         }

                         else {

                                                  txtMins.text = “”;

                         }

                         txtMins.appendText(String(min));

                         if (sec < 10) {

                                                  txtSecs.text = “0″;

                         }

                         else {

                                                  txtSecs.text = “”;

                         }

                         txtSecs.appendText(String(sec));

                         txtDate.text = now.toDateString();

}


time.start();

 

Now test your movie and you can see your system time on your movie display.

Try this!.

Categories: AS3 Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.