0
votes

I have a background sound that I play from main frame (frame 1). This is the script:

var bscucok1:Sound = new bscucok(); 
var channelbscucok:SoundChannel = bscucok1.play();

The background sound was playing, but I want to stop the sound when the movie clip inside this frame (frame 1) finishes (frame 200).

channel1bscucok.stop();

doesn't work; this one does:

import flash.media.SoundMixer;
SoundMixer.stopAll();

but I don't want to stop other sounds, only the background sound.

1

1 Answers

0
votes

You need to explicitly state which sound you want to stop using the soundchannel class.

If you're using Flash Professional: Right click the sound in the library, click 'Properties', tick 'Export for Actionscript', enter a class name (this can be the same name as the sound), click 'ok'.

Now, remove the sound from the timeline, because you'll be programming it to play/pause/stop from now on. Firstly, add the following to frame 1 of the movie you want to play the sound on:

var mySound:Sound = new [The class name you gave the sound without brackets]();

The variable 'mySound' is now the actionscript reference to the sound that you want to play. You can only use it to play this sound, but you can create other variables the same way to create other sounds.

Now, whenever you want to play the sound use:

var mySoundChannel:SoundChannel = mySound.play(0);

And to stop the sound use:

mySoundChannel.stop();

The variable 'mySoundChannel' is directly linked to the sound, and any interactions with this variable will only make changes to the sound you assign to the variable.