Flash Countdown System

Source: Internet
Author: User

In this example, only the calculation method of countdown is introduced

As for native storage, we'll talk about it in the next class.



Train of thought: 1. Create a text for the output time;
2. Instantiate a date class with the given parameter as the countdown time;
3. To find out the millisecond number of the difference by the new system time with the countdown time minus the changing;
4. Finally learn milliseconds-seconds-minutes-hours-days between conversions.



Add as code:
_root.createtextfield ("TXT", 1, 150, 150, 0, 0);
Txt.autosize = true;
Create a text box to output time
var year = 2008;
var month = 8;
var date = 8;
var hour = 20;
var minute = 0;
var second = 0;
Set timed time (this example takes the Beijing Olympics as the countdown)
var end:date = new Date (year, month-1, date, hour, minute, second);
The Date class instantiation specifies the day and time as milliseconds, so the month (0~11) is reduced by 1


_root.onenterframe = function () {

var now:date = new Date ();
Get current date and time (in milliseconds)



var dif = (End-now)/1000;
Calculates the number of milliseconds between the two, divided by 1000 into the number of seconds



var dif_d = Math.floor (dif/(3600*24));
Number of days =[difference total seconds/day total seconds (60 seconds *60 * 24 hours)]



var dif_h = Math.floor ((dif-dif_d*3600*24)/3600);
The difference in hours =[(total number of seconds left after the number of days)/total seconds in one hour]



var dif_m = Math.floor ((dif-dif_d*3600*24-dif_h*3600)/60);
Minute =[(total number of seconds left in days and hours after rounding)/total seconds in one minute]



var dif_s = Math.floor (dif-dif_d*3600*24-dif_h*3600-dif_m*60);
Number of seconds =[days and hours and minutes after rounding total seconds left



Txt.text = dif_d+ "Days" +dif_h+ "hours" +dif_m+ "minutes" +dif_s+ "seconds";
};



Flash Charge: Date class Introduction
Constructors for the 1.Date class
Public Date ([Yearortimevalue:number], [Month:number], [Date:number], [Hour:number],[minute:number], [Second:number] , [Millisecond:number])



2. The parameters in the constructor
Yearortimevalue:number [Optional]: If additional parameters are specified, this number represents the year (for example, 1965). If the number represents

The time value (no other parameter specified) is the number of milliseconds before or after 0:00:00 January 1, 1970.

Month:number [optional]: An integer between 0 (January) and 11 (December).

Date:number [optional]: An integer from 1 to 31.

Hour:number [optional]: An integer between 0 (midnight) and 23 (11 o'clock in the evening).

Minute:number [optional]: An integer from 0 to 59.

Second:number [optional]: An integer from 0 to 59.

Millisecond:number [optional]: integer (milliseconds) from 0 to 999.



3. Example

Example 1:
var d1:date = new Date ();
The Date object is set to the time the assignment statement was run.
Trace (D1)
return: Tue Dec 22:35:38 gmt+0800 2007



Example 2:
var d2:date = new Date (2000, 0, 1);
Creates a date object using the year, month, and date parameters that pass the Date object.

Trace (D2)
Back: Sat 1 00:00:00 gmt+0800 2000



Example 3:
var d1:date = new Date ();
var d2:date = new Date (2000, 0, 1);
var dif = D1-d2
Trace (DIF);
The number of milliseconds to return the difference: 251332873437



Example 4: The same result can be obtained through the gettime () function
var d1:date = new Date ();
var d2:date = new Date (2000, 0, 1);
var dif = D1.gettime ()-d2.gettime ();
Trace (DIF);
The number of milliseconds to return the difference: 251332873437

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.