# BPM Sync

**URL:** <https://forum.kirupa.com/t/bpm-sync/254417>\
**Category:** flash\
**Created:** [March 11, 2008, 10:25pm UTC](https://forum.kirupa.com/t/bpm-sync/254417 "2008-03-11T22:25:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![FlashHed](https://avatars.discourse-cdn.com/v4/letter/f/e480ec/32.png) [@FlashHed](https://forum.kirupa.com/u/FlashHed)\
**Post date:** [March 11, 2008, 10:25pm UTC](https://forum.kirupa.com/t/bpm-sync/254417/1 "2008-03-11T22:25:09Z")

</div>

Hi All,

Just wondering if anyone here has had any experience with BPM syncing animations using as3? This is as far as I have got so far. Any suggestions as to how to improve this, or links to some good tutorials would be greatly appreciated.

Thanks

/\*

- Create an FLA and place lines at every 50px mark on the y axis starting at 100px

- Also you need a click track done in a program like reason or fruity loops with the  
linkage Record1 in your library

\*/

stop ();

import flash.media._;  
import flash.display._;  
import flash.events._;  
import flash.utils.Timer;  
import flash.events.TimerEvent;  
import fl.transitions._;  
import fl.transitions.easing.\*;  
import flash.utils.setTimeout;

var bpm:Number = 96;  
var minute:Number = 60000;  
var beatMS:Number = minute / bpm;  
var barMS:Number = (beatMS \* 4);  
var ballList:Array = [];  
var i:int;  
var t:Timer  
var rec1:Sound = new Record1 as Sound;

createBalls ();

t = new Timer(beatMS,999);  
t.start ();

var isPlaying:Boolean = false;

t.addEventListener (TimerEvent.TIMER,updateTimer);  
t.addEventListener (TimerEvent.TIMER\_COMPLETE,resetTimer);

function createBalls () {

```
for (i = 0; i &lt; 5; i++) {

    var balls:Sprite = this['ball'+i] as Sprite;
    balls = new Sprite();
    balls.graphics.beginFill (0xff0000,1.0);
    balls.graphics.drawCircle (10,(barMS/100) * i,5);
    balls.y -= (barMS/100)
    balls.graphics.endFill ();
    addChild (balls);
    ballList.push (balls);
}

```

}  
function updateTimer (event:TimerEvent):void {

```
if (!isPlaying) {

    isPlaying = true;
    rec1.play (0,999);

}
for (i = 0; i &lt; ballList.length; i++) {

    ballList*.y += (barMS/ 100);

}
event.updateAfterEvent ();

```

}  
function resetTimer (event:TimerEvent):void {

```
t.reset ();
event.updateAfterEvent ();

```

}
