0
votes

I hava a .fla file with 2 scenes, on the first scene i have a song playing in the back which stops whenever an user presses a button(btnP). The button takes the user to another scene(Scene2).

The first scene works fine and when the program goes to the other Scene the music stops. But, i want a different sound on Scene2. If i try to use the same technique on Scene2, nothing happpens. Both my sound files are imported to the library.

Heres my code for Scene1 (This works).

import flash.media.Sound;
import flash.media.SoundMixer;
stop();

btnP.addEventListener(MouseEvent.CLICK, petterVelg);

var snd:Sound =
new Sound(new URLRequest("lifted.mp3"));

snd.play();



function petterVelg(e:MouseEvent){

    gotoAndPlay(1, "Scene 2");
    SoundMixer.stopAll();

} 

Here is mye code for Scene 2( This does not play any audio at all.... )

import flash.media.Sound;
var snd2:Sound = new Sound(new URLRequest("drikke.mp3"));
snd2.play();
1

1 Answers

0
votes

You should use the SoundChannel class:

stop();

var snd:Sound = new Sound(new URLRequest("lifted.mp3"));
var piste1:SoundChannel = new SoundChannel();
piste1 = snd.play();

btnP.addEventListener(MouseEvent.CLICK, petterVelg);

function petterVelg(e:MouseEvent):void
{
    gotoAndStop(1, "Scene 2");
    piste1.stop();
}