Copy link to clipboard
Copied
I have streaming audio on each frame that automatically starts and stops when the next or previous frame is clicked. I need to add a pause button on each frame. I have created a play/pause toggle movie clip on my first frame and it works fine. Frame one uses mySound1 and myChannel1, frame two uses mySound2 and myChannel2, etc.
When I try to add the code to the next frame I get errors. What do I need to do to have a button on each frame to stop the corresponding mp3? I appreciate your help!
SoundMixer.stopAll();
var pP:Number = 0;//playback position
var playing:Boolean = false;
var mySound1:Sound = new Sound();
var myChannel1:SoundChannel = new SoundChannel();
mySound1.load(new URLRequest("Physiology Slide 01 INTRO.mp3"));
myChannel1 = mySound1.play();
SoundMixer.stopAll();
PlayPause_btn.addEventListener(MouseEvent.CLICK, togglePlay);
togglePlay(null);
function togglePlay(event:MouseEvent):void {
playing = !playing;
if (playing) playS();
else pauseS();
}
function playS() {
myChannel1 = mySound1.play(pP);
PlayPause_btn.gotoAndStop(2);
}
function pauseS() {
pP = myChannel1.position;
myChannel1.stop();
PlayPause_btn.gotoAndStop(1);
}
are you using the same function names (ie, togglePlay, playS and pauseS) on your keyframes? if so, you'll see a duplicate function error (1120, i think).
to remedy, use different function names or use a switch/case or if/else sequence in one of each function.
Copy link to clipboard
Copied
are you using the same function names (ie, togglePlay, playS and pauseS) on your keyframes? if so, you'll see a duplicate function error (1120, i think).
to remedy, use different function names or use a switch/case or if/else sequence in one of each function.
Copy link to clipboard
Copied
I have this on the next frame but the button doesn't work.
SoundMixer.stopAll();
var mySound2:Sound = new Sound();
var myChannel2:SoundChannel = new SoundChannel();
mySound2.load(new URLRequest("Physiology Slide 02.mp3"));
myChannel2 = mySound2.play();
PlayPause_btn.addEventListener(MouseEvent.CLICK, togglePlay2);
togglePlay2(null);
function togglePlay2(event:MouseEvent):void {
playing = !playing;
if (playing) playS();
else pauseS();
}
function playS2() {
myChannel2 = mySound2.play(pP);
PlayPause_btn.gotoAndStop(2);
}
function pauseS2() {
pP = myChannel2.position;
myChannel2.stop();
PlayPause_btn.gotoAndStop(1);
}
Copy link to clipboard
Copied
you're using the same name for that button.
if that's in a frame 2 keyframe, give it a different name. if it's the same button as the frame 1 button, remove the frame 1 listener.
Copy link to clipboard
Copied
Thank you!
I am a beginner with actionscript and I had tried different combinations of code. The button works now but the sound doesn't automatically start playing on the second frame like the first frame.
The only other question I have is - is it possible to go back to the previous or next frame and play where the sound was paused? For now it just starts over.
Thank you so much for assistance.
Copy link to clipboard
Copied
yes.
in each keyframe where you have a sound, assign a different variable to store the value of your soundchannel's position:
SoundMixer.stopAll();
var mySound2:Sound = new Sound();
var myChannel2:SoundChannel = new SoundChannel();
mySound2.load(new URLRequest("Physiology Slide 02.mp3"));
var sound2_position:Number;
if(!isNaN(sound2_position)){
myChannel2 = mySound2.play(sound2_position);
} else{
myChannel2 = mySound2.play();
}
// just before leaving this frame, assign:
sound2_position=myChannel2.position;
Copy link to clipboard
Copied
The code works for pause and play but the sound in the next frame won't play automatically. How do I get the sound to start on the next frame without hitting the play button? I can't remove SoundMixer.stopAll(); or the first frame keeps playing.
Frame2:
SoundMixer.stopAll();
var pP2:Number = 0;//playback position
var playing2:Boolean = false;
var mySound2:Sound = new Sound();
var myChannel2:SoundChannel = new SoundChannel();
mySound2.load(new URLRequest("Physiology Slide 02.mp3"));
myChannel2 = mySound2.play();
SoundMixer.stopAll();
PlayPause2_btn.addEventListener(MouseEvent.CLICK, togglePlay2);
togglePlay2(null);
function togglePlay2(event:MouseEvent):void {
playing = !playing;
if (playing) playS2();
else pauseS2();
}
function playS2() {
myChannel2 = mySound2.play(pP);
PlayPause2_btn.gotoAndStop(1);
}
function pauseS2() {
pP2 = myChannel2.position;
myChannel2.stop();
PlayPause2_btn.gotoAndStop(2);
}
Copy link to clipboard
Copied
use the code i suggested.
Copy link to clipboard
Copied
I really, really appreciate your help. You are awesome. But the code works except when I go to the next frame the new audio begins at the time the last frame was paused and not the beginning. SO close…
Copy link to clipboard
Copied
show the code you're using on two frames that contain the relevant code.
Copy link to clipboard
Copied
Frame 1:
SoundMixer.stopAll();
var pP:Number = 0;//playback position
var playing:Boolean = false;
var mySound1:Sound = new Sound();
var myChannel1:SoundChannel = new SoundChannel();
mySound1.load(new URLRequest("Physiology Slide 01 INTRO.mp3"));
myChannel1 = mySound1.play();
SoundMixer.stopAll();
PlayPause_btn.addEventListener(MouseEvent.CLICK, togglePlay);
togglePlay(null);
function togglePlay(event:MouseEvent):void {
playing = !playing;
if (playing) playS();
else pauseS();
}
function playS() {
myChannel1 = mySound1.play(pP);
PlayPause_btn.gotoAndStop(2);
}
function pauseS() {
pP = myChannel1.position;
myChannel1.stop();
PlayPause_btn.gotoAndStop(1);
}
Frame2:
home_button1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_45);
function fl_ClickToGoToAndStopAtFrame_45(event:MouseEvent):void
{
gotoAndStop(3);
}
muscles_tab.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_7);
function fl_ClickToGoToAndStopAtFrame_7(event:MouseEvent):void
{
gotoAndStop(10);
}
wrong_tab.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_8);
function fl_ClickToGoToAndStopAtFrame_8(event:MouseEvent):void
{
gotoAndStop(29);
}
healing_tab.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_9);
function fl_ClickToGoToAndStopAtFrame_9(event:MouseEvent):void
{
gotoAndStop(45);
}
conclusion_tab.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_10);
function fl_ClickToGoToAndStopAtFrame_10(event:MouseEvent):void
{
gotoAndStop(69);
}
home_button1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_94);
function fl_ClickToGoToAndStopAtFrame_94(event:MouseEvent):void
{
gotoAndStop(3);
}
SoundMixer.stopAll();
var pP2:Number = 0;//playback position
var playing2:Boolean = false;
var mySound2:Sound = new Sound();
var myChannel2:SoundChannel = new SoundChannel();
mySound2.load(new URLRequest("Physiology Slide 02.mp3"));
myChannel2 = mySound2.play();
var sound2_position:Number;
if(!isNaN(sound2_position)){
myChannel2 = mySound2.play(sound2_position);
} else{
myChannel2 = mySound2.play();
}
SoundMixer.stopAll();
PlayPause2_btn.addEventListener(MouseEvent.CLICK, togglePlay2);
togglePlay2(null);
function togglePlay2(event:MouseEvent):void {
playing = !playing;
if (playing) playS2();
else pauseS2();
}
function playS2() {
myChannel2 = mySound2.play(pP);
PlayPause2_btn.gotoAndStop(1);
}
function pauseS2() {
pP2 = myChannel2.position;
myChannel2.stop();
PlayPause2_btn.gotoAndStop(2);
}
sound2_position=myChannel2.position;
Copy link to clipboard
Copied
it looks like you're using the suggested code on one frame (2) and it's used there incorrectly.
to have it work on frames 1 and 2, use:
Frame 1:
SoundMixer.stopAll();
var pP:Number = 0;//playback position
var playing:Boolean = false;
var mySound1:Sound = new Sound();
var myChannel1:SoundChannel = new SoundChannel();
mySound1.load(new URLRequest("Physiology Slide 01 INTRO.mp3"));
//myChannel2 = mySound2.play();
var sound1_position:Number;
if(!isNaN(sound1_position)){
myChannel1 = mySound1.play(sound1_position);
} else{
myChannel1 = mySound1.play();
}
SoundMixer.stopAll();
PlayPause_btn.addEventListener(MouseEvent.CLICK, togglePlay);
togglePlay(null);
function togglePlay(event:MouseEvent):void {
playing = !playing;
if (playing) playS();
else pauseS();
}
function playS() {
myChannel1 = mySound1.play(pP);
PlayPause_btn.gotoAndStop(2);
}
function pauseS() {
pP = myChannel1.position;
myChannel1.stop();
PlayPause_btn.gotoAndStop(1);
}
// i don't see any code that changes the frame. but wherever that is, put
sound1_position=myChannel1.position;
Frame2:
home_button1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_45);
function fl_ClickToGoToAndStopAtFrame_45(event:MouseEvent):void
{
gotoAndStop(3);
}
muscles_tab.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_7);
function fl_ClickToGoToAndStopAtFrame_7(event:MouseEvent):void
{
gotoAndStop(10);
}
wrong_tab.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_8);
function fl_ClickToGoToAndStopAtFrame_8(event:MouseEvent):void
{
gotoAndStop(29);
}
healing_tab.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_9);
function fl_ClickToGoToAndStopAtFrame_9(event:MouseEvent):void
{
gotoAndStop(45);
}
conclusion_tab.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_10);
function fl_ClickToGoToAndStopAtFrame_10(event:MouseEvent):void
{
gotoAndStop(69);
}
home_button1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_94);
function fl_ClickToGoToAndStopAtFrame_94(event:MouseEvent):void
{
gotoAndStop(3);
}
SoundMixer.stopAll();
var pP2:Number = 0;//playback position
var playing2:Boolean = false;
var mySound2:Sound = new Sound();
var myChannel2:SoundChannel = new SoundChannel();
mySound2.load(new URLRequest("Physiology Slide 02.mp3"));
//myChannel2 = mySound2.play();
var sound2_position:Number;
if(!isNaN(sound2_position)){
myChannel2 = mySound2.play(sound2_position);
} else{
myChannel2 = mySound2.play();
}
SoundMixer.stopAll();
PlayPause2_btn.addEventListener(MouseEvent.CLICK, togglePlay2);
togglePlay2(null);
function togglePlay2(event:MouseEvent):void {
playing = !playing;
if (playing) playS2();
else pauseS2();
}
function playS2() {
myChannel2 = mySound2.play(pP);
PlayPause2_btn.gotoAndStop(1);
}
function pauseS2() {
pP2 = myChannel2.position;
myChannel2.stop();
PlayPause2_btn.gotoAndStop(2);
}
// again, i don't see any code that changes the frame. but wherever that is, put
sound2_position=myChannel2.position;
// likewise for all your other frames with similar code
Copy link to clipboard
Copied
Thank you!
There was something strange going on when I tried you original suggestion which was an easy fix. I ended up using it on a different file and the it worked. I redid all the frames on the other file and no problem. That was a nightmare over nothing.
One last problem though…The audio still doesn't stay paused after leaving the frame.
THANK YOU for you help!
Copy link to clipboard
Copied
you mean if you enter a frame, the audio plays and that's what you want.
you pause the audio, exit the frame and then reenter the frame and the sound starts playing. that's not what you want?
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Copy link to clipboard
Copied
pause the audio, exit the frame and then reenter the frame where the pause button left off.
Copy link to clipboard
Copied
that's another different problem.
you should mark whatever answers were helpful/correct to answer the original questions and start a new thread. this one is getting lenghty.
Copy link to clipboard
Copied
Thanks!
Copy link to clipboard
Copied
you're welcome.
(but it doesn't make sense to mark that one as correct.)
Copy link to clipboard
Copied
I changed it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now