flex组件 倒计时为零自我删除的方法

sdata 是接受后端传来的数据;
  要点:this.parent.removeChild(this)的使用
   <?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="35" height="40" horizontalScrollPolicy="off" verticalScrollPolicy="off"
      creationComplete="init()">
<mx:Script>
  <![CDATA[
   [Bindable]
   public var imgUrl:String='';
   [Bindable]
   public var timer:String = '';
   [Bindable]
   public var gid:String='';
   
   [Bindable]
   public var sdata:Object={};
   
   private var t:int;
   private var timer1:Timer;
   public function init():void
   {
    var coloArr:Array = sdata['show'].split('_');
    var coloStr:String = '';
    //获得最后一位值进行判断 进而对颜色赋值
    if(coloArr[coloArr.length-1] == '1'){
     coloStr = '#FFFFFF';
    }else if(coloArr[coloArr.length-1] == '2'){
     coloStr = '#009EFF'; 
    }else{
     coloStr = '#FF9E00';
    }
    txt.setStyle("color", coloStr);//设置文本字体颜色
    //在sdata中取出时间
    t = sdata['time'];
    txt.text = transadvanceTime(t);//对时间进行换算
    if(t>0)
    {
     timer1 = new Timer(1000);
     timer1.addEventListener(TimerEvent.TIMER,timerHandler1);
     timer1.start()      
    }
   }
   
   private function timerHandler1(event:TimerEvent):void
   {
    if(t>0)
    {
     t--
     txt.text = transadvanceTime(t);
    }
    else
    {
     if(timer1)
     {
      timer1.removeEventListener(TimerEvent.TIMER,timerHandler1);
      timer1.stop();
      timer1 = null
     }
     this.parent.removeChild(this);//重点:时间停止了移除自身
    }  网页游戏:http://www.shengshiyouxi.com
   }
   
   private function transadvanceTime(timeNum:Number):String
   {
     var total_seconds:uint = Math.floor(timeNum);
     var total_minutes:uint = Math.floor(total_seconds/60);
     var total_hours:uint = Math.floor(total_minutes/60);
     var total_days:uint = Math.floor(total_hours/24);
     var days:uint = total_days;
     var hours:uint = total_hours%24;
     var minutes:uint = total_minutes%60;
     var seconds:uint = total_seconds%60;
     return (hours<10?"0"+hours:hours.toString())+":"+(minutes<10?"0"+minutes:minutes.toString());
      }   
   
  ]]>
</mx:Script>
<mx:Image x="5" y="1" width="25" height="25" source="{imgUrl}" visible="{gid==''?false:true}" mouseChildren="false"/>
<mx:Text id="txt" x="1" y="22"  width="100%" fontSize="11" color="#ffffff" fontWeight="normal"  mouseChildren="false"/>
</mx:Canvas>

 

                                                 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值