I have a SoundHandler class with the following variables:
private static var musicChannel: SoundChannel;
private static var effectsChannel: SoundChannel;
private static var narrationChannel: SoundChannel;
private static var narrationMuted:Boolean;
In the initialize function:
var classReference: Class = getDefinitionByName(narrationClassName) as Class;
var s: Sound = new classReference();
narrationChannel = s.play();
The effects and music channels work fine, but the narration channel doesn't stop when stop() is called. Here is the function:
public static function playNarration(narrationClassName: String): void {
if (!narrationMuted) {
narrationChannel.stop(); //NOT WORKING--THE SOUND KEEPS PLAYING!
var classReference: Class = getDefinitionByName(narrationClassName) as Class;
var s: Sound = new classReference();
narrationChannel = s.play();
}
}
SoundMixer.stopAll() DOES stop the narration sound, but I can't use it because it also stops the music and effects sounds.
I suspect that stop() isn't working because of how I'm creating the Sound object, but I'm not sure. Loading externally doesn't fix the problem:
public static function playNarration(narrationClassName: String): void {
if (!narrationMuted) {
narrationChannel.stop();
var s: Sound = new Sound();
s.addEventListener(Event.COMPLETE, onNarrationSoundLoaded);
var req: URLRequest = new URLRequest("sounds/Narration/sub_narr_1.mp3");
s.load(req);
}
}
private static function onNarrationSoundLoaded(e: Event): void {
var localSound: Sound = e.target as Sound;
narrationChannel = localSound.play();
}
Keeping the narration sounds as static variables doesn't work either:
private static var subNarr1:Sound;
public static function playNarration(narrationClassName: String): void {
if (!narrationMuted) {
narrationChannel.stop();
narrationChannel = subNarr1.play();
}
}
Any help is appreciated. Thanks!