Question

I have a timer and a dynamic textfield wich displays the time. Everytime my movieclip hits an enemy I want the timer to add 4 sec. to the current count. I would like to know why this isn't working:

timer.currentCount + 4;

(does nothing)

timer.currentCount += 4;

(error: property is read-only)

Am I in the right direction anyway and what should I change?

Was it helpful?

Solution

As stated in the other answer you can't adjust the elapsed time of your Timer. What you could try to do is create a seperate var you call var elapsedTime:Number; every time the timer ticks you add 1 to this var. When the hittest occurs you can simply add 4 to it.

Because you're using a var to 'manipulate' the the time you don't need to use the currentCount anymore. Just refer to elapsedTime in an update function and you'll be fine.

It'll look like this:

var timer:Timer = new Timer(1000);
var elapsedTime:Number = 0;

timer.addEventListener(TimerEvent.TIMER, onTimerTick);

function onTimerTick(e:TimerEvent) : void
{
    elapsedTime++;
    updateTimerTxt();
}

function onHitTest() : void
{
    elapsedTime += 4;
    updateTimerTxt();
}

function updateTimerTxt() : void
{
    timertxt.text = String(elapsedTime);
}

OTHER TIPS

The property currentCount is read only. There is no way you can modify the elapsed time of a timer. If you need to modify the timer then you can stop that and create a new one with modified interval.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top