flex 定时器:setTimeout / setInterval

原文地址:http://hi.baidu.com/runthu/blog/item/d685d65c32310547fbf2c0d9.html

flex 定时器:setTimeout / setInterval
2008-01-24 21:35
执行一次:

flash.utils.setTimeout(function():void{Alert.show("only show once");}, 2000, null);
重复执行:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
initialize="initTimter()"
backgroundGradientColors="[#67cbff, #fcffff]" 
color="#000000"
   paddingTop="0"
   paddingLeft="0"
   paddingRight="0"
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
   public var count:Number=30; //定义时间长度(秒)
   public var intervalId:Number;//定时器参数
   //定时器起动口
   public function initTimter():void
   {
    intervalId = setInterval(doTimter,1000);
   }
   //定时器回调方法
   public function doTimter():void
   {
    showLabel.text = count.toString() + "second to go";
    count -= 1;
    if(count == 0){
        showLabel.text = count.toString() + "second to go";
     clearInterval(intervalId);
    trace("Time is up");
    }
   }
 

]]>
</mx:Script>
<mx:Label id="showLabel"/>
</mx:Application>

你可能感兴趣的:(xml,Flex,Flash,UP,Go)