views:

218

answers:

1

I have an issue with an Actionscript 2 piece of code. I'm trying to load a song and start playing it at the 50th second until the end.

var song:Sound = new Sound();
song.setVolume(100);
song.loadSound(songToPlay,true); // songToPlay is a valid path
song.start(50);

This loads and play the Sound, but at the begining and not at 50 seconds like I want. I also tried

song.start(50,1);

without success.

What am I doing wrong?

+1  A: 

In order to start a sound file at a specific time, you have to start it after it's finished loading (or at least loaded past that point).

Try something like this:

var song:Sound = new Sound();
song.setVolume(100);
song.onLoad = function(success:Boolean) 
{
   if (success) 
   {
      song.start(50);
   } 
};
song.loadSound(songToPlay,true);
Gerald
it worked, thanks a lot! that will save me so much time
marcgg
No problem. Actually I believe you could also just set "false" in your loadSound function, which would essentially have the same effect. (Specifying "true" means that it's a streaming sound and can begin playing as soon as it starts downloading.)
Gerald