Flex中如何通过setTimeout()和clearTimeout()函数创建timers计时器的例子

By Minidxer | April 5, 2009

接下来的例子演示了Flex中如何通过setTimeout()和clearTimeout()函数,创建timers计时器。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white">
  6.  
  7.     <mx:Script>
  8.         <![CDATA[
  9.             import mx.controls.Alert;
  10.  
  11.             private var alert:Alert;
  12.  
  13.             private function delayedAlert():void {
  14.                 setTimeout(launchAlert, 2000);
  15.                 button.enabled = false;
  16.             }
  17.  
  18.             private function launchAlert():void {
  19.                 alert = Alert.show("I'm an alert.");
  20.                 button.enabled = true;
  21.             }
  22.         ]]>
  23.     </mx:Script>
  24.  
  25.     <mx:Button id="button"
  26.             label="Click here to launch alert (2 second delay)"
  27.             click="delayedAlert();" />
  28.  
  29. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Other | 7 Comments » | 1,133 views Tags: ,

你可能还对下列文章感兴趣:

7 comments | Add One

  1. 雪深 - 04/6/2009 at 9:35 am

    看不懂

  2. Minidxer - 04/6/2009 at 10:08 am

    灌水居然灌到这里。。。

  3. 雪深 - 04/6/2009 at 6:48 pm

    我申请链接的帖子呢?

  4. Minidxer - 04/6/2009 at 7:23 pm

    友情链接吗?不做这种事情已经很久了,呵呵

  5. 雪深 - 04/9/2009 at 10:01 am

    做一个啦 就一个啦

    看起来你的pr不低,我的也不是特别低啊!

  6. yansy115 - 05/19/2009 at 5:26 pm

    很郁闷~~
    为什么我的flex跑这段程序就会出错误啊!!

  7. yansy115 - 05/20/2009 at 6:25 pm

    flash.utils.setTimeout(launchAlert, 2000);
    打败了,莫非我的版本问题?必须在前面加上flash.utils.~~
    难道大家的都运行正常吗?

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts