[Hundreds of lines of code for games] timerevent and rotation applications in actionscript3.0 [personal hour hands]

Source: Internet
Author: User
Tags flv file

 

1. Create an actionscript3.0 FLV File
2. Insert --> Create component hour,


Vertex correlation


Use the toolbar to draw a clockwise drawing and try to draw it at the registration point in the center.


3. Similarly, create a minute component.
Draw a needle splitting image

4. Create a second component.
Draw a second-hand Image


5. Create a biaopan component.
Any drawing of a dial with its own personality

6. Add the actionscript3.0 script code by pressing F9

VaR now: Date = new date (); // obtain the local time var now_hour = now. gethours (); // obtain the time value. var now_minute = now in 24-hour format. getminutes (); // obtain the value var now_second = now. getseconds (); // obtain the second value var angle_second = now_second/60/* 360; // convert the value to the dial scale var angle_minute = now_minute/60*360; vaR angle_hour = (now_hour + now_minute/60)/12*360; var biaopan: biaopan = new biaopan (); // create a previously drawn biaopan Element Object var hour: hour = new hour (); // create a previously drawn hour Element Object var minute: minute = new minute (); // create a previously drawn minute Element Object var second: second = new second (); // create a previously drawn second Element Object addchild (biaopan); addchild (hour); addchild (minute); addchild (second); biaopan. X = stage. stagewidth/2; biaopan. y = stage. stageheight/2; hour. X = stage. stagewidth/2; hour. y = stage. stageheight/2; minute. X = stage. stagewidth/2; minute. y = stage. stageheight/2; second. X = stage. stagewidth/2; second. y = stage. stageheight/2; hour. rotation = angle_hour; // The Position of the initial pointer minute. rotation = angle_minute; second. rotation = angle_second; var Timer: timer; timer = new timer (1000); // execute the timer function timehandlertimer per second. addeventlistener (timerevent. timer, timehandler); timer. start (); function timehandler (E: Event): void {second. rotation + = 6; // seconds to convert the second to 6 degrees minute. rotation + = 6/60; // The minute needle is transferred to 6/60 degrees hour per second. rotation + = 6/3600; // The hourly hour turns to 6/3600 degrees per second}

7. Work Effect

8. Work presentation address: http://up.qqhello.com/qzone/22c991982d981e4cebc857715921f479.swf

 

Method 2: refresh the local time each time and directly update the latest position of the image.

VaR biaopan: biaopan = new biaopan (); // create a previously drawn biaopan Element Object var hour: hour = new hour (); // create a previously drawn hour Element Object var minute: minute = new minute (); // create a previously drawn minute Element Object var Second: Second = new second (); // create a previously drawn second Element Object var Timer: timer; timer = new timer (1000); // execute the timer function timehandlertimer per second. addeventlistener (timerevent. timer, timehandler); timer. start (); function timehandler (E: Event): void {var now: Date = new date (); // obtain the local time var now_hour = now. gethours (); // obtain the time value. var now_minute = now in 24-hour format. getminutes (); // obtain the value var now_second = now. getseconds (); // obtain the second value var angle_second = now_second/60*360; // convert the value to the dial scale var angle_minute = now_minute/60*360; vaR angle_hour = (now_hour + now_minute/60)/12*360; biaopan. X = stage. stagewidth/2; biaopan. y = stage. stageheight/2; hour. X = stage. stagewidth/2; hour. y = stage. stageheight/2; minute. X = stage. stagewidth/2; minute. y = stage. stageheight/2; second. X = stage. stagewidth/2; second. y = stage. stageheight/2; hour. rotation = angle_hour; // The Position of the initial pointer minute. rotation = angle_minute; second. rotation = angle_second; addchild (biaopan); addchild (hour); addchild (minute); addchild (second )}

 

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.