I can't get an object to flash exactly 154 times every minute.
I'm doing a flash game to go with this song on a band's website (sweet band, by the way (www.lessages.com)), and the song would be playing during the game, and I want certain events to go with the beat of the song, and that would be so much easier if I could get a metronome on my flash project, and I'm running into problems with that.
I can't get an object to flash exactly 154 times every minute, because the song plays at a constant rate of 154 beats per minute. It's always a little bit off, so that after about 30 seconds, it ceases to be on beat. The object that I want to blink is called "blinker." Here is my actionscript:
Code:
var beatTimer = new Timer(60000/154); // A timer for how often I want it to appear (154 times every minute, or 154 times every 60,000 milliseconds)
var disappearTimer = new Timer(20, 1); // A timer for how long I want it to remain before it dissapears (20 milliseconds)
blinker.alpha = 0; // blinker starts out invisible
beatTimer.start(); // beatTimer starts the moment the swf starts
beatTimer.addEventListener(TimerEvent.TIMER, tickTock);
disappearTimer.addEventListener(TimerEvent.TIMER_COMPLETE, disappear);
function tickTock(e:TimerEvent):void { // What I want flashplayer to do every time it cycles through beatTimer
trace("tick");
blinker.alpha = 100; // Show blinker
disappearTimer.start(); // Set blinker to disappear in 20 milliseconds
}
function disappear(e:TimerEvent):void {
blinker.alpha = 0; // after 20 milliseconds, blinker disappears
}