Flash example tutorial for clock making

Source: Internet
Author: User
Tags time and date time interval

This example is to use flash AS3.0 to make the example of the clock tutorial, for the Flash as an introductory tutorial in the eighth lesson of the extended course, hoping to bring help to friends.

AS3.0 Example Tutorial Two-making of clocks

Effect:

Although the production clock is a bit cliché, it can be applied more fully to the knowledge of time, date and interval, which is still a good introductory practice.

I. Introduction to AS3.0 time and date

Time and date are mainly applied in two aspects of the read time date and the setup interval. The time date in AS3.0 is still read with the date class, which is more convenient than the AS2.0 3.0 to get the time date. Similarly, to use the date class, you first create an instance of the class, such as:

var nowtime:date = new Date ();

This obtains an instance of date: Nowtime

Call some properties of the date instance directly to get the current date and time, for example:

Nowtime.fullyear Current year

Nowtime.month+1 the current month, the value of the Month property is 0-11, so it should be month+1 to get the current month.

Nowtime.date Current Day

Nowtime.day Current week value is 0-6

Nowtime.hours Current Hour

Nowtime. Minutes Current minute

Nowtime. Seconds Current Second

The Timer class is the most commonly used setting of time intervals in AS3.0.

First, create an instance of the Timer class:

var instance name: Timer = new Timer (number of milliseconds in interval, [repeat times]);

For example, we're going to set a time interval of 5 seconds to perform every 1 seconds:

var jg:timer = new Timer (1000,5);

If you do not set a repeat count parameter, it will never stop at every interval of time.

When you create a timer instance, you use the instance to listen for a timer event to invoke the function:

Jg. AddEventListener (TIMEREVENT.TIMER,SC);

This will call the SC function once every second, and call it 5 times altogether.

Also need to use a sentence:

Jg.start ();

The timer instance starts to start.

The action to be performed is defined in a function, such as the SC function above:

Format: Function functions name (event:timerevent): void{

The action to perform

}

The following is a complete application of the timer class code:

var i = 0;

var jg:timer = new Timer (1000,5);

Jg. AddEventListener (TIMEREVENT.TIMER,SC);

Jg.start ();

function SC (event:timerevent): void {

i++;

Trace (i);

}

Paste the above code in the first frame, test the movie, each second will output a number, 5 seconds after the end of the run, the final result is:

1

2

3

4

5

Second, the production of the clock:

According to the drawing of a good clock face and pointer, hand hour, minute hand, second hand are MC, registration point in the bottom of the middle, the instance name is SZ_MC,FZ_MC,MZ_MC

Year month days a total of 4 dynamic text boxes, the instance name is: Y_txt,m_txt,d_txt,w_txt

var dqtime:timer = new Timer (1000);

function XSSJ (event:timerevent): void{

var sj:date = new Date ();

var nf = sj.fullyear;

var YF = sj.month+1;

var rq = sj.date;

var xq = Sj.day;

var h = sj.hours;

var m = sj.minutes;

var s = sj.seconds;

var axq:array = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

Y_txt.text = NF;

M_txt.text = YF;

D_txt.text = RQ;

W_txt.text = Axq[xq];

if (h>12) {

h=h-12;

}

Sz_mc.rotation = H*30+M/2;

Fz_mc.rotation= M*6+S/10;

Mz_mc.rotation = s*6;

}

Dqtime.addeventlistener (TIMEREVENT.TIMER,XSSJ);

Dqtime.start ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.