Time and date of ActionScript writing

Source: Internet
Author: User
Tags date final getdate local time min variable time and date
Date in FLASH MX built-in date functions provide us with the ability to get or modify dates and times. (Note: The time obtained is the system time and date of the local computer) some basic commands and explanations are listed below.

First, the basic order and explanation of the date and time
getFullYear () returns the number of years of 4 digits per local time.
GetMonth () returns the number of months by local time.
GetDate () Returns the day of the month according to local time.
GetHours () returns the hour value in local time.
Getminutes () returns the minute value in local time.
Getseconds () returns the number of seconds per local time.
The above commands are not difficult to understand, are to obtain the local machine date and time. But to use these commands, we must first create an instance of a Date object with the constructor function of the Date object. Then, you can use this instance that you created to do the operation! The command format is as follows:
Instance name =new Date ()

Second, show the date and make a walking table
Here's an example that describes the various command usage methods for the Date object. ( source File Download)
The final effect is as follows:

Steps:
1, a new flash document, the layer 1 renamed to: Text display, and in the stage below draw a dynamic text box, starting a variable name: MyTime The following figure:

2. Create a new layer and name the new layer: the dial, and then use the drawing tool to draw a dial with no minute, hour, and second hand on the stage. The following figure:

3, now to draw the pointer. Press Ctrl+f8 to create a new movie clip, named: pointer, select the Drawing tool, in which the vertical draw a thin line as a pointer. Note: Align the bottom of the line with the center point of the movie clip! The following figure

4, to return to the main stage, a new layer, renamed: pointer-seconds drag and drop the pointer in the middle of the dial, and note that the center point of the Pointer is aligned with the center of the dial. After that, a name for this pointer instance is: SEC We do the second hand first. The following figure:

5, the same, and then create a new layer, and the name is: pointer-points to the library of "pointer" components and then drag and drop out, and change the length and color of this instance, let it as the minute hand. The instance name is: Min The following figure:

6, now according to the above method to make the hour clock, a new layer, renamed as: pointer-When the pointer components dragged on the stage, and the center of the dial to align, and the example named: Hour the following figure:

7, Oh, now we began to write programs, in order to observe the convenience, we create a new layer, renamed as, select as layer of the first frame, open the action panel, start writing script, first of all, we want to let the dynamic text box on the stage display date and time.
_root.onenterframe = function () {//You need to keep the movie running the following script.
MyDate = new Date ()//First build a Date object named MyDate, because we will use mydate this instance to control.
Myear = Mydate.getfullyear ()//Gets the year on the local machine and places it in the myear variable.
Mmon = Mydate.getmonth () +1;//gets the month on the local machine and places it in the Mmon variable. Because the value obtained is 0 for January, 1 for February, and so on, so add 1 to the correct
Mdate = Mydate.getdate ()//Gets the day ordinal of the month on the local machine and places it in the mdate variable.
MOU = mydate.gethours ()//Gets the number of hours on the local machine, in the MOU variable, which gets the value between 0--23.
mm = Mydate.getminutes ()//Gets the number of minutes on the local machine and places it in the MM variable.
ms = Mydate.getseconds ()//Gets the number of seconds on the local machine and places it in the MS variable.
MyTime = myear+ "year" +mmon+ "month" +mdate+ "Day" +mou+ ":" +mm+ ":" +MS; Let the dynamic text box with the variable name mytime on the stage display the date and time.
}
Now you can test, you can find the stage on the text box will show the date and time, then there is a table inside the seconds, minutes, and how the clock corresponds to the time? Now we add the following script: (Put in mytie= .....) below that line)
Sec._rotation = 6*ms;//uses the object Rotation command in Flash to make the pointer move around. _rotation rotation is 360 degrees a week, so, the second hand every walk, is equal to go 6 degrees, so use an algorithm to get the degree of 6*ms
Min._rotation = 6*mm;//The same, so that the minute hand is also based on the number of minutes obtained by multiplying the 6来 of the degree of rotation.
Hour._rotation = mou*30+mm/60*30;//hours of walking, the algorithm is a little more complicated, because the hour hand to walk a lap is 12 large lattice. The specific above algorithm interested friends can study it for themselves.
The final complete script is shown below:

Conclusion: the date and time of as writing is not complicated, here I simply explained the acquisition date and time. , of course, we can also make changes to the date and time settings, the use of commands and methods to obtain similar, interested friends can refer to some of the Flash script reference books. I hope you can use this simple example to master the basic date and time as the preparation.

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.