I have created a flash header that is pulling some external sound from a server and am running into an interesting issue.
Here is the code that I am using.
function music(){
var my_sound = new Sound();
my_sound.loadSound("01Track1.mp3", true);
my_sound.onLoad = function(){
_root.createTextField("time", 10, 825, 360, 0, 0);
var dTotal = this.duration/1000;
var dMin = Math.floor(dTotal/60);
var dSec = Math.floor(dTotal)%60;
if (dSec<10){
dSec = "0" + dSec;
};
var txt_format = new TextFormat();
txt_format.size = 10;
txt_format.font = "Arial";
txt_format.color = 0xFFFFFF;
onEnterFrame = function(){
var pTotal = my_sound.position/1000;
var pMin = Math.floor(pTotal/60);
var pSec = Math.floor(pTotal)%60;
if (pSec<10) {
pSec = "0" + pSec;
};
time.selectable = false;
time.autoSize = true;
time.text = (pMin + ":" + pSec) + " / " + (dMin + ":" + dSec);
time.setTextFormat(txt_format);
};
my_sound.start();
control.onRelease = function(testTime){
if(this._currentframe == 1){
stopAllSounds();
this.gotoAndStop(2);
}else if(this._currentframe == 2){
var freeze = my_sound.position;
my_sound.start(freeze/1000);
this.gotoAndStop(1);
};
};
};
};
And here is what is happening:
I have a preloader on the first frame and after everything is loaded it goes to the second frame and begins playing. If I just preview the movie in flash (Ctrl + Enter) then everything works fine; the music plays my text field is created (the time counts correctly), and the start/stop button works fine.
If I then go up to “Simulate Download” to test the preloader and everything, when it loads and goes to the second frame, the music will sometimes play (and cut out), the text field isn’t created, the start/stop button doesn’t work, and I don’t know what the problem is.
I think I have pinned it down to my my_sound.onLoad() function (that I don’t think is getting run in the simulated download), but I can’t figure out why it would work with a live preview, and not a simulated download.
Thanks to anyone who could help shed some light on this. I have spent a lot of time trying to figure it out before coming here.