Skip navigation
maxwellmb
Currently Being Moderated

Stop other sounds from playing while current sound is playing

Apr 10, 2011 3:25 AM

Hi

I am creating a game that has 6 movieclips all on the main time line of the game.

Each movie clip has three buttons that when clicked plays, pauses or stops a sound clip.

When I press any of the sound clip play buttons that sound starts playing, the problem

is when I click any of the other sound clip play buttons those sounds also start to play.

Is there a way I can disable the other sound clip buttons while the current sound is

playing then enable all of the buttons when the current sound has stopped.

 

This is the code that creates one of the sound objects

 

firstSound = new Sound(firstSoundMc);
firstSound.attachSound("sound1");
myMusicVolume=100;
firstSound.setVolume(myMusicVolume);

 

This is the code on the play button

 

on (press) {
//Sound is not playing and has not been paused
if (playing!=true) {
if (paused!=true) {
playing=true;
paused=false;
stopped=false;
firstSound.start(0,0);
} //closes paused!=true
//
//Sound has been paused
if (paused==true) {
playing=true;
paused=false;
stopped=false;
firstSound.start(myMusicPosition,0); 
this.firstSound.onSoundComplete = function(){
firstSound.start(0,0); 
}
 
} //Closes paused==true
//
//END
}//Closes playing!=true
//
}//Closes on press

 

Best Regards Maxwellmb

 

 
Replies
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 10, 2011 7:11 AM   in reply to maxwellmb

    1.  remove all code from objects.

     

    2.  assign instance names to your objects that need to respond to code

     

    3.  you can use the enabled property of your buttons to disable (when a sound starts) and re-enable (when a sound completes) them.

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 11, 2011 8:08 AM   in reply to maxwellmb

    your code will work if this.firstSound is your sound instance declared before your onSoundComplete and onSoundComplete is defined before this.firstSound.start().

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points