开发者

Use variables to set timer, as3

开发者 https://www.devze.com 2022-12-26 23:34 出处:网络
How can I use variables to set my timer? I want to control delay and repeat as variable. My output acts as if there is nothing set in the timer.

How can I use variables to set my timer? I want to control delay and repeat as variable. My output acts as if there is nothing set in the timer.

Not working variables

var timer:Timer = new Timer(delay,repeat);
var delay:uint = 100;
var repeat:uint = 60;
开发者_开发技巧

Works Fine no variables

var timer:Timer = new Timer(1000,60);

Complete Unexpected results. Counts to thousands within seconds.

var timer:Timer = new Timer(delay, repeat);
var delay:uint = 1000;
var repeat:uint = 60;
timer.addEventListener(TimerEvent.TIMER, countdown);
function countdown(event:TimerEvent) {
myText.text = String(0 + timer.currentCount);
trace(0 + timer.currentCount);
}
timer.start();


I think it is because you are declaring your variables after you create your timer instance. try...

var delay:uint = 1000;
var repeat:uint = 60;
var timer:Timer = new Timer(delay, repeat);
0

精彩评论

暂无评论...
验证码 换一张
取 消