So, my looping sound code is ddriving me nuts. It works perfectly when I test it by building in the Flash IDE using Ctrl + Enter, but the second I try running the game in a standalone player, looped sounds either don't loop or don't play. I'm at my wits' end trying to figure out why it works in the IDE player but not in a standalone projector.
Below is my music code: it checks the name of the track to be loaded against an array that contains the music's location, then loads the appropriate mp3 from that location and tells it to loop (minus 50 milliseconds off the front and back end to prevent popping).
function playMusic () {
Music.stop();
if (musicOn == true && currTrack !== "") {
for (i = 0; i < 50; i++) {
if (currTrack == songIndex[i][0]) {
targetSongURL = songIndex[i][1];
}
}
Music = new Sound();
Music.loadSound(targetSongURL, true);
//Looping code
var leader:Number = 50; // milliseconds gap at the start of the mp3
var follower:Number = 50; // milliseconds gap at the end of the mp3
var placeToStop:Number;
Music.onLoad = function(){
Music.start();
placeToStop = Music.duration - follower; //tell it where to loop
// run interval to constantly check the position of the mp3
// and restart after the initial mp3 gap.
var intervalVal:Number = setInterval( checkForLooping , 5 ); //run checkForLooping every 5 milliseconds
function checkForLooping():Void{
if (Music.position > placeToStop) { //if it's past the loop point
Music.stop();
Music.start(leader / 1000); //restart 50 milliseconds in
}
}
}
}
}
Any ideas why this would work in the IDE player but not in the standalone player? (And yes, before anyone says anything, this is AS2. And yes, I know AS2 sucks.)