?
Solved

Sound Toggle For Video Clip

Posted on 2003-02-28
6
Medium Priority
?
185 Views
Last Modified: 2010-04-03
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
0
Comment
Question by:rimbaud
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:Zeffer
ID: 8045963
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

0
 
LVL 6

Expert Comment

by:henryww
ID: 8047108
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
0
 
LVL 6

Expert Comment

by:henryww
ID: 8047114
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rimbaud
ID: 8059188
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.
0
 
LVL 6

Accepted Solution

by:
henryww earned 400 total points
ID: 8059301
sorry ... i was not using ur code, the clip names are different .. i was just giving an example

the fact that, if u have a movieclip with an event sound, u can stop it but it won't start again ... i don't know why, it maybe a bug or something.

ok if u want it exactly in ur code ...

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

on(release){
   
if (sounds == 0) {
 _root.firstSound.setVolume(0);
 _root.sounds = 1;
 }
 
else {
 _root.firstSound.setVolume(100);
 _root.sounds = 0;
}
}
that's how i'd turn off the volume instead


as for the second methond mentioned, here u will have to remove the event sound from the movieclip and export the sound, call "s" or whatever u like

//frame 1 _root
var snd2Pos = 0;
var snd2 = new Sound()
snd2.attachSound("s"); // attach the sound from library
// if u don't need the loop remove the whole function
snd2.onSoundComplete = function (){
   snd2.start(0,1);     // looping the sound
}

//starts playing
snd2.start(0,1);
// i suppose u can start ur movieclip here too, so the sound & the movie can sync

// sound toggle button
on (release) {
   if (_root.snd2Pos ==0) {
   // stop the sound and remember where it is stopped
   _root.snd2Pos = _root.snd2.position / 1000
   // now if u want to stop the movieclip as well
   // do this _root.mcVideo.stop();
   _root.snd2.stop("s");
   } else {
  // start again
  // and to start the movieclip _root.mcVideo.play();
   _root.snd2.start(_root.snd2Pos,1);
   _root.snd2Pos = 0
   }
}

use the attachSound u can stop /start the sound object, but then u will have to manually stop the movieclip as well if it is a VO, ... synchronise the sound & movie is also a very tricky thing, so u need to fine tune it and adjust the frame rate etc ...

cheers
0
 

Author Comment

by:rimbaud
ID: 8059597
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
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question