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/