[Flash Basic theory Lesson 12] Countdown system [GetTime]

Source: Internet
Author: User

Back to "flash Basic Theory Class-Catalog"

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])

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.