flex组件 倒计时为零自我删除的方法
发布时间:2020-12-15 04:47:10 所属栏目:百科 来源:网络整理
导读:?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
?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);//重点:时间停止了移除自身 } } 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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |