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