Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : Detect when a sound plays


Attomm
5/7/2004 7:49:14 PM
Is there a way to detect when a movie is playing a sound.

For example I have a root movie that has background music, from that movie
you can load an SWF file into it and view that file. If the SWF file that I
load contains any sounds then I want to turn my background music off, otherwise
I want to leave it on.

I'm actually wanting to check if a sound is playing from an embedded flash
member within Director, but I can get the above solution to work I will be able
to get to work in Director as well.

Is the Sound.onload() the way to do this? I would need to create and assign
this object to the child movies?

Please offer any suggestions if you have them.

Thanks,
Adam

Shan-Dysigns
5/7/2004 11:21:26 PM
For your background sound:

somevar=new Sound();
somevar.loadSound(blah blah);
somevar.start();
_root.somevariable="playing";
somevar.onSoundComplete=funciton () {
_root.somevariable="not playing";
}

Then on your other mc that has music:

if (_root.somevariable!="playing") {
someothervar=new Sound();
someothervar.loadSound(blah blah);
someothervar.start();
}

Something to that effect will work...

Attomm
5/10/2004 12:49:01 PM
Thank you very much for the code sample. I read through my orginal post and I
didn't emphasize the fact that I will not actually create the SWF files... or
provide input to the person that creates them. Is there a way to detect if a
sound is playing without setting my own variable.

I can still send script commands to the movies (_child.whatever) but I won't
actually start the sound playing.

Imagine I go to flashkit.com and download 10 random SWF files. I insert these
into my movie with background music, if one of those SWF files starts playing
audio I want to stop my background music, otherwise I want it to keep playing.

In Director there is a SoundBusy() function that will tell you if a certain
sound channel is being used or not.

Any other thoughts?


Thank again,
Adam
Attomm
5/10/2004 4:50:34 PM
I should also note that I am able to create a new Sound Object in the arbitrary
SWF file and can control its volume from my master movie. Still doesn't tell
me if there is a sound actually playing but is one step closer.
AddThis Social Bookmark Button