Java and flex Study Notes (14) -- Implement countdown in flex

Source: Internet
Author: User

Previously, I wanted to implement the countdown effect. I thought it was quite easy. I didn't expect it to be difficult. Finally, I realized this effect using network resources.


I originally thought that there is a setTimeout () function in flex, which means to run the specified function after the specified delay (in milliseconds), that is


    public function setTimeout(closure:Function, delay:Number,... arguments):Uint


However, if the countdown is made, only one number is reduced. I don't know if it is because flex runs one frame. Helpless. I would like to express my gratitude for the effect of the Countdown by modifying a countdown resource on the Internet. Create an mxml file and check the code shown in the following section of the original file:


<? XML version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx" preloader = "ases. util. loadingprogressbarutil "width =" 100% "Height =" 100% "creationcomplete =" app_creationcompletehandler (event) "> <FX: style source =" CSS/activateemail.css "/> <FX: SCRIPT> <! [CDATA [Public var Timer: timer; [Bindable] public var STR: string; protected function app_creationcompletehandler (Event: flexevent): void {timer = new timer (1000 ); // set the interval to 1 s timer. addeventlistener (timerevent. timer, timehandle)} // call the countdown method private function starttimer (): void {timer. start () ;}// the stop countdown method private function stoptimer (): void {timer. stop ();} // Private function timetransform (stattime: int, c Ounter: INT): String {var STR: String = ""; var count: Int = stattime-counter; var Second: Int = count % 60; STR = (second + "") + "s and return to the home page... "; if (second = 0) {isstop = true; // you can add the processing method at the end of the Countdown here. STR = "Please wait, jump... "Var URL: URLRequest = new URLRequest (" http: // localhost: 9080/mydisk/SWF/login.html "); navigatetoURL (URL," _ Self ");} else {isstop = false;} return STR;} private function timehandle (E: timerevent): void {var count: Int = timer. currentcount; STR = timetransform (6, count); If (isstop) {stoptimer () ;}< s: labelid = "back" text = "{STR}"/> </S: Application>

 

The code for implementing countdown is posted above. It can be seen that the effect is to instantiate a timer object first, and then implement the effect by listening to timer. Call the starttimer () method when we need to display the countdown. Otherwise, call the stoptimer () method. For some comments, see the code.


The effect is as follows:



 


Original article, reproduced please indicate the source: http://www.dianfusoft.com/





Related Article

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.