Synchronizing music with animation

I have created a movieclip that runs with a music file. I need the animation to move in time to the music. My first difficulty is how can I finetune the animation to move precisely in time to the beat of the music (without constantly testing and tweaking)?

Next, assuming I am satisfied with the way the animation runs in time to the music, if I run this movie from within another movie (using loadMovie) and then upload to my web server and run from a browser, the music and the animation never run together consistently.
The animation may run slower than the music, and the whole synchronization is lost.
Is there a better way to do this?