0

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;
}
}
4
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by almostbob
0

This should be pretty self-explanatory. Here's your code again, I've commented out a line of code which should stop your sound from auto-playing:

var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0; 
var soundIsPlaying:Boolean = true;
mySound.load(new URLRequest("Intro1.mp3"));

//Line below not needed:
//myChannel = mySound.play();
// after removing this, the sound will not play until the 
// play button has been clicked.
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;
}
}

Cheers for now,
Jas.

0

thanks for that. but i have a problem now where the when i go to another page the sound files when played overlap?

0

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

0

You could try using SoundMixer.stopAll();

So when the user navigates to a new page, ensure that SoundMixer.stopAll() is called before the new sound is started. That should stop any sounds that are currently playing; regardless of whether they're external or in the library.

To use SoundMixer, you'll need to use the following import:

import flash.media.SoundMixer;

Cheers for now,
Jas.

0

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.

0

good one.....................................

This should be pretty self-explanatory. Here's your code again, I've commented out a line of code which should stop your sound from auto-playing:

var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0; 
var soundIsPlaying:Boolean = true;
mySound.load(new URLRequest("Intro1.mp3"));

//Line below not needed:
//myChannel = mySound.play();
// after removing this, the sound will not play until the 
// play button has been clicked.
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;
}
}

Cheers for now,
Jas.

0

this seems to be a classic problem that i have never seen a solution that works and still no luck i'm afraid.

0

solution: dont put sounds on the web page,

there are enough annoying useless crap sites, there is no requirement for any more

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.