Stop sound from automatically playing?
want to know what code snippet you could add to this code to stop my sound file from playing automatically when you enter that frame?
code:
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
var soundIsPlaying:Boolean = true;
mySound.load(new URLRequest("Intro1.mp3"));
myChannel = mySound.play();
offBtn.addEventListener(MouseEvent.CLICK, onClickStop);
function onClickStop(e:MouseEvent):void{
myChannel.stop();
soundIsPlaying = false;
}
offBtn.addEventListener(MouseEvent.CLICK, onClickPause);
function onClickPause(e:MouseEvent):void{
lastPosition = myChannel.position;
myChannel.stop();
soundIsPlaying = false;
}
onBtn.addEventListener(MouseEvent.CLICK, onClickPlay);
function onClickPlay(e:MouseEvent):void{
if(!soundIsPlaying){
myChannel = mySound.play(lastPosition);
soundIsPlaying = true;
}
}
snitch321
Junior Poster in Training
63 posts since Nov 2007
Reputation Points: 9
Solved Threads: 2
thanks for that. but i have a problem now where the when i go to another page the sound files when played overlap?
snitch321
Junior Poster in Training
63 posts since Nov 2007
Reputation Points: 9
Solved Threads: 2
I read up that playing external sounds causes this overlapping glitch. So maybe you could give me some code to play the sound from the library?
thank you jason
snitch321
Junior Poster in Training
63 posts since Nov 2007
Reputation Points: 9
Solved Threads: 2
well i actually abandoned this idea of playing sound because i added your code yet the sound still overlaps. It's weird, when i move to a new frame and the sound automatically begins playing its fine, but when i then stop it and play it manually it then overlaps. so if you have a solution it would be good but dont try too hard since im abandoning this idea.
snitch321
Junior Poster in Training
63 posts since Nov 2007
Reputation Points: 9
Solved Threads: 2
this seems to be a classic problem that i have never seen a solution that works and still no luck i'm afraid.
snitch321
Junior Poster in Training
63 posts since Nov 2007
Reputation Points: 9
Solved Threads: 2
solution: dont put sounds on the web page,
there are enough annoying useless crap sites, there is no requirement for any more
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376