Stop looping audio on key press

Note: this is being published as a Mac projector file.

I am trying to play some audio while a portion of my movie loops. Looping ends and the movie advances to the next section (frame label “beseated”) when the right arrow or page up key is pressed.

If the key is pressed before the looping frames start over (i.e., goes back to frame 1), the audio stops as it should and the movie advances to the next section.

But, if I let it loop and go back to frame 1, upon the key press the movie advances to the the next section correctly but the music does not stop as I would expect…

Below is the code in the first frame of the movie, which starts the audio playing and listens for key presses.

stop();

//start music
var my_sound:SoundId = new SoundId();
var my_channel:SoundChannel = new SoundChannel();
my_channel = my_sound.play();

//listen for key press
stage.addEventListener(KeyboardEvent.KEY_DOWN, startPresentation);

function startPresentation(e:KeyboardEvent):void {
    if (e.keyCode==34 || e.keyCode==39) {
        //stop playing audio and advance past the looping frames
        my_channel.stop();
        gotoAndStop("beseated");
    }
}

Any assistance would be greatly appreciated :slight_smile: