PDA

View Full Version : AS3 timer inaccuracy - alternatives?


akanik
12-08-2007, 07:23 PM
Currently, I'm working on a 16 step sample sequencer in flash CS3.

I'm using the following code to execute a function which plays the
appropriate samples. This function is called based on the tempo, which
is set by the user. The value of 150 is not static.

...

var metronome:Timer = new Timer(150,0);
metronome.addEventListener(TimerEvent.TIMER,playSt eps);

...

Problem is, the timer is totally inaccurate. You can audibly hear it speeding up and slowing down the execution times, rendering my project frustratingly useless.

Is there an alternative method (ANY POSSIBLE WAY) to execute my function at small millisecond intervals without this ridiculous inaccuracy in timing?

This is for a final project and is the ONLY remaining issue with the program.

Thanks for ANY help.

- Nick

jaga
12-08-2007, 07:46 PM
simplest possible solution is to increase your framerate

akanik
12-08-2007, 07:56 PM
I've increased the rate from 15 to 45, 60, 90, 120.

Each time the inaccuracy changes, but doesn't diminish =(

jaga
12-08-2007, 08:05 PM
Just doing a quick test, yeah framerate doesn't affect it.

I also get a varying range of time its triggered at..


import flash.events.*;
import flash.utils.*;

var myTimer:Timer = new Timer(100,0);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, myFunction);

function myFunction(whichEvent:Event):void {
trace("Update at time " + getTimer());
}


plop that into flash and you can see its not even close to happening every 100ms..