Problem with starting a Sound at a specified position (AS2)
-
06-07-2019 - |
Question
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?
Solution
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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow