Link to home
Start Free TrialLog in
Avatar of rimbaud
rimbaud

asked on

Sound Toggle For Video Clip

Hi all.
Before I inquired about a play/pause toggle button for a video clip, which I got help with.
Now I am having trouble with a play/pause toggle for the sound in that video clip, as opposed to a toggle for independent sound. My button pauses the sound, but won't restart it.

I have placed the video clip in a movie clip in _root called mcVideo.
On frame 1 of _root, I set:

sounds = 0;
firstSound=new Sound(_root.mcVideo);

Then, on the mute button (also on _root), I set:

on(release){
     
if (sounds == 0) {
  _root.firstSound.stop();
  _root.sounds = 1;
  }
 
 else {
  _root.firstSound.start();
  _root.sounds = 0;
 }
 
}


Thank you
Avatar of Zeffer
Zeffer
Flag of New Zealand image

change the 'else' to another 'if statement ..

on(release){
   
if (sounds == 0) {
 _root.firstSound.stop();
 _root.sounds = 1;
 }
 
if (sounds == 1) {
 _root.firstSound.start();
 _root.sounds = 0;
 }

}

Z

Avatar of henryww
henryww

hi all,

i had tried using stop/start with a movieclip target, but i can't get it to start playing either.

sorry if i am ignorant, i don't see any different between using the "else" and the extra "if".

in this particular case, if the sound is a loop then i would sugguest set the volume to 0 then 100 again to as to turn it on/off

// frame1 _root
snd = new Sound(_root.myMc);
sndstop = 0;

// button
on (release) {
     if (_root.sndstop == 0) {
     _root.sndstop = 1
     _root.snd.setVolume(0);
     trace("volume = " + _root.snd.getVolume());
     } else {
     _root.sndstop = 0
     _root.snd.setVolume(100);
     trace("volume = " + root.snd.getVolume());
     }
}


otherwise if u really have to stop & start at the same position. use sound object & attach the sound.

//frame 1 _root
var snd2Pos = 0;
var snd2 = new Sound()
snd2.attachSound("s");
snd2.onSoundComplete = function (){
     snd2.start(0,1);    
}

// sound toggle button
on (release) {
     if (_root.snd2Pos ==0) {
     _root.snd2Pos = _root.snd2.position / 1000
     _root.snd2.stop("s");
     trace("stop :"+  _root.snd2Pos);
     } else {
     trace("play :"+  _root.snd2Pos);
     _root.snd2.start(_root.snd2Pos,1);
     _root.snd2Pos = 0
     }
}
snd2.start(0,1);


cheers
sorry the correct post should be

otherwise if u really have to stop & start at the same position. use sound object & attach the sound.

//frame 1 _root
var snd2Pos = 0;
var snd2 = new Sound()
snd2.attachSound("s");
snd2.onSoundComplete = function (){
    snd2.start(0,1);    
}
snd2.start(0,1); // **** this line here

// sound toggle button
on (release) {
    if (_root.snd2Pos ==0) {
    _root.snd2Pos = _root.snd2.position / 1000
    _root.snd2.stop("s");
    trace("stop :"+  _root.snd2Pos);
    } else {
    trace("play :"+  _root.snd2Pos);
    _root.snd2.start(_root.snd2Pos,1);
    _root.snd2Pos = 0
    }
}

copy & paste error ... he he he
Avatar of rimbaud

ASKER

Thanks guys, but no luck yet.

Zeffer, the change in keyword to "if" didn't change anything.

Henry, when I implement your code, the sound doesn't stop and I get the error message "stop :0"
Maybe I implemented it wrong?
The movie clip is called "mcVideo," and I don't see that represented in your code. I also tried passing the new Sound() object the parameter _root.mcVideo, but that didn't work.

Again, this is a video clip with voiceover sound that I placed inside a movie clip. I have had success turning the sound off with the simple code listed in my first email, but can't turn it back on after that.
ASKER CERTIFIED SOLUTION
Avatar of henryww
henryww

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rimbaud

ASKER

The first method works great and is actually fine for my purposes. But the second method is great to know for the future. Many thanks!

-rimbaud