Question about stopping sound
Hi,
We have a file where the user must make a sound when a circle and rectangle hittest. When this happens, a sound should play. Afterwards, the sound should turn off. We can't get the sound to turn off. Can you help us? I've inserted the code below, all contained on frame 1 of our file.
Code:
import flash.media.Sound;
/* Microphone is turned on, it has all the settings so that it doesn't sound funny.
On the stage I'm going to wait for an event with an event listener.
The listener will run a function whenever the playhead enters a frame where the listener is present.
The function will make a movieclip undergo a geometric transformation tied to the microphone's activity level.
*/
var myMic:Microphone = Microphone.getMicrophone();
Security.showSettings(SecurityPanel.MICROPHONE);
myMic.setLoopBack(true);
myMic.setUseEchoSuppression(true);
//Set up sound
var s1:Sound = new soundOne();
//declare sound channel variable
var myChannel:SoundChannel = new SoundChannel();
//set up sound channel
myChannel = s1.play();
myChannel.stop();
//Code from frame 2
//Each time it enters a frame then run the code
stage.addEventListener(Event.ENTER_FRAME, stage_EnterFrame);
function stage_EnterFrame(e:Event)
{
trace(myMic.activityLevel);
//to get the microphone to sense noise
//alter the line below for minimum noise level
//If bird squawks while ball and box are touching then display bridge (check mark)
if (myMic.activityLevel >50 && (ball.hitTestObject(box)))
{
//play our sound
myChannel = s1.play();
checkMark.alpha = 1;
}
else
{
checkMark.alpha = 0;
//somehow get sound to stop playing
myChannel.stop();
}
}