# Beat Mixer & Song Playback

**URL:** <https://forum.kirupa.com/t/beat-mixer-song-playback/218823>\
**Category:** flash\
**Created:** [March 11, 2007, 3:03pm UTC](https://forum.kirupa.com/t/beat-mixer-song-playback/218823 "2007-03-11T15:03:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonanin](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@jonanin](https://forum.kirupa.com/u/jonanin)\
**Post date:** [March 11, 2007, 3:03pm UTC](https://forum.kirupa.com/t/beat-mixer-song-playback/218823/1 "2007-03-11T15:03:39Z")

</div>

Hello kirupa!=)

Okay, well I’m making this little thing called BeatBox. Basically you get to create little beats in a mixer, then submit them to a “portal” where people can rate them and listen to them.

You can see it so far here: [http://flash.jonanin.com/music.html](http://flash.jonanin.com/music.html)

Anyways, If you play it, you can see it lags and the music is a bit out of sync when you play it. So, I need help optimizing my code a bit!

For song playback, I use setTimeout and step through a 2-dimensional array at each interval. For each step, I use a for loop and loop through every block in the column it is currently being played and check if that block in the array is a 1. If its a 1, that means the block is “on” and should be played, and I start the sound for it.

heres the code:

```auto
playSongPart = function() {
    
    for (var i=0; i < _root.map.length; i++) {
                // if the current place in the map array is a 1, that means that that we should play a sound because it is "On". Otherwise it would be 0.
        if (_root.map*[_root.step] == 1) {
                        // play the song
            _root.sounds*.start(0,0);
        }
    }
        // this just moves the little red playhead thing.
    ph._x = rx + (bw/2) - bw + .5 + ((step)*bw);

    _root.step++;
        // loop the song when its reached the end
    if (_root.step > _root.song_len) {
        _root.playSong();
    }
}

```

Is there a better way to do this? I really need help optimizing my code so that it doesn’t lag – especially on older computers.

Thanks in advance,  
Jon
