質問

I am creating a Flash project that includes a timer. I am using the Timer class, but when I test the project the text goes from 00 to 0 instead of going to 01. In Flash, I have created 2 text fields, for minutes and seconds; I have only made the cod for the second timer. My code is:

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";
        }
    }
}

}

役に立ちましたか?

解決

convert an integer to a string as3

Have you tried using e.currentTarget.currentCount.toString() instead of String(e.currentTarget.currentCount)?

EDIT: actually you shouldn't even need to use string conversion to concatenate an int to a string

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top