AS3 flash disabled

I am using Flash CS4 with AS3. I want the timer to call a function at intervals of 50 ms 100 times. however, the timer takes much longer than it should, which adds up to 1677 ms (1,677 seconds!) too much after 100 repeats. I missed something here or the timer, WHAT is inaccurate?

the code

function test(event:TimerEvent):void{
   trace("GetTimer(): " + getTimer() + " || Timer.currentCount: " + _timer.currentCount);
}

var _timer:Timer = new Timer(50, 100); 
_timer.addEventListener(TimerEvent.TIMER, test); 
_timer.start();

Trace Output:

GetTimer (): 74 || Timer.currentCount: 1

GetTimer (): 140 || Timer.currentCount: 2

GetTimer (): 209 || Timer.currentCount: 3

GetTimer (): 275 || Timer.currentCount: 4

GetTimer (): 340 || Timer.currentCount: 5

GetTimer (): 407 || Timer.currentCount: 6

GetTimer (): 476 || Timer.currentCount: 7

GetTimer (): 542 || Timer.currentCount: 8

GetTimer (): 608 || Timer.currentCount: 9

GetTimer (): 677 || Timer.currentCount: 10

......

GetTimer (): 3340 || Timer.currentCount: 50

......

GetTimer(): 6677 || Timer.currentCount: 100

.

,

+3
4

Timer . Flash - , . this . 50 , getTimer() ENTER_FRAME, , .

+8

. SWF, , .

+1

, (1000/fps) . 1:

var counter:int = 0;
const COUNT_TO_INVOKE: int = 2;//if calling every 3 frames
function onEnterFrame(e: Event):void{
    counter++;
    if(counter == COUNT_TO_INVOKE){
        timerFunction();
        counter = 0; 
    }
}
0

Source: https://habr.com/ru/post/1770688/


All Articles