在Flash中创建倒数计时器时出错

时间:2015-11-13 21:05:02

标签: actionscript-3 flash timer flash-cs5.5

我正在尝试使用我发现的代码在Flash CS5.5中添加计时器。但似乎我纠正的错误很少,但我的输出仍然无法正常工作。错误是访问txt的undefined属性。  任何人都可以帮我看看吗?提前谢谢!

@noticias = Notice.where('tags && ARRAY[?]::varchar[]',current_authority.tags)

这是我的zip文件。 https://www.dropbox.com/s/evm5alnbypty41y/Untitled-3.rar?dl=0

1 个答案:

答案 0 :(得分:0)

只需在舞台上添加文字并将其命名为“txt”

通过在行开头添加这些行来以编程方式执行此操作

 import flash.text.TextField;

 var txt:TextField = new TextField ;
 txt.embedFonts = true ;
 addChild(txt);

使用以下代码(经过测试)

           import flash.utils.Timer;
           import flash.events.TimerEvent;

      var seconds:int ;
      var minutes:int ;
      var totalTimeInSeconds:int 
      var ticker:int ;


 var tmr:Timer ;

 function timerFunction(minutes, seconds)

 {
  totalTimeInSeconds = minutes * 60 + seconds
tmr = new Timer (1000,totalTimeInSeconds);
tmr.addEventListener(TimerEvent.TIMER,timerClick);
tmr.addEventListener(TimerEvent.TIMER_COMPLETE,timerComplete) ;
tmr.start() ;

}

 timerFunction(2, 15)
 function timerClick (e:TimerEvent):void
 {
 var curMinute:int = Math.floor((totalTimeInSeconds - ticker)/60) ;
 var curSecond:int =  (totalTimeInSeconds - ticker) -  (curMinute*60)  ;
 txt.text =  curMinute + ":" + curSecond;
 ticker +=1 ;
 }

 function timerComplete (E:TimerEvent):void
 {  
   txt.text = "0:0" ;
   tmr.removeEventListener(TimerEvent.TIMER,timerClick);
   tmr.removeEventListener(TimerEvent.TIMER_COMPLETE,timerComplete) ;
 }