我正在创建一个包含计时器的Flash项目。我正在使用Timer类,但是当我测试项目时,文本从00变为0而不是01.在Flash中,我创建了2个文本字段,分钟和秒;我只为第二个计时器制作了鳕鱼。我的代码是:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.text.TextField;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Demolition extends MovieClip {
private var _secTimer:Timer = new Timer(1000, 60);
private var _minTimer:Timer = new Timer(60000);
public var _sec:TextField;
public var _min:TextField;
public function Demolition() {
_secTimer.start();
_secTimer.addEventListener(TimerEvent.TIMER, secTimer);
addEventListener(MouseEvent.RIGHT_CLICK, rightClickHandler);
addEventListener(Event.ENTER_FRAME, frameHandler);
}
private function rightClickHandler(e:MouseEvent) {
}
private function frameHandler(e:Event) {
}
private function secTimer(e:TimerEvent) {
trace(e.currentTarget.currentCount);
if (e.currentTarget.currentCount < 10) {
_sec.text = "0" + String(e.currentTarget.currentCount);
} else if (e.currentTarget.currentCount == 60) {
_secTimer.reset();
_sec.text = "00";
}
}
}
}
答案 0 :(得分:0)
convert an integer to a string as3
你试过用过吗?
e.currentTarget.currentCount.toString()
代替
String(e.currentTarget.currentCount)
?
编辑:实际上你甚至不需要使用字符串转换来将int连接到字符串