7 Replies - 1550 Views - Last Post: 05 April 2011 - 04:44 PM

#1 [email protected]   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 23-March 11

Activate play buttons when sounds complete playing

Posted 30 March 2011 - 04:35 AM

I currently have a game that allows the player to Start, Stop and Pause sound clips.
Currently the Start button only becomes active after the Stop button has been pressed.
I would also like the Start buttons to become active as soon as the sounds complete playing.


This is the code on frame 1 of the main timeline that creates two sound objects

firstSound = new Sound(firstSoundMc);
firstSound.attachSound("sound1");
myMusicVolume=100;
firstSound.setVolume(myMusicVolume);
this.onEnterFrame = function () {
if (stopped!=true) {
myMusicDurationText=_root.firstSound.duration/1000;
myMusicPositionText=_root.firstSound.position/1000;
}
}

secondSound = new Sound(secondSoundMc);
secondSound.attachSound("sound2");
myMusicVolume2=100;
secondSound.setVolume(myMusicVolume2);
this.onEnterFrame = function () {
if (stopped!=true) {
myMusicDurationText2=_root.secondSound.duration/1000;
myMusicPositionText2=_root.secondSound.position/1000;
}
}


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;
myConditionText="Playing";
firstSound.start(0); 
//
} //closes paused!=true
//
//Sound has been paused
if (paused==true) { 
playing=true; 
paused=false; 
stopped=false;
firstSound.start(myMusicPosition,0); 
myConditionText="Playing";
_root.firstSound.onSoundComplete = function() { 
firstSound.start();

} //Closes function
} //Closes paused==true
//
//END
}//Closes playing!=true
//
}/


This is the code on pause button

on (press) {
//Pause Button
if (pause!=true) {
playing=false;
paused=true;
stopped=false
myConditionText="Paused";
myMusicPosition=_root.firstSound.position/1000;
_root.firstSound.stop("sound1");
}
}


This is the code on the stop button

on (press) {
//Stop Button
playing=false;
paused=false;
stopped=true;
myConditionText="Stopped";
_root.firstSound.stop("sound1");
myMusicPosition=0;
myMusicPositionText=0
} 


Is This A Good Question/Topic? 0
  • +

Replies To: Activate play buttons when sounds complete playing

#2 chinchang   User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 727
  • Joined: 22-December 08

Re: Activate play buttons when sounds complete playing

Posted 30 March 2011 - 05:39 AM

Attach a listener to your sound object's onSoundComplete event. Inside the listener function disable the stop buttton and enable the start button.
Was This Post Helpful? 0
  • +
  • -

#3 [email protected]   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 23-March 11

Re: Activate play buttons when sounds complete playing

Posted 30 March 2011 - 10:50 AM

Hi
I tried adding in a listener as you pointed out.
Although I'm sure my syntax is not correct as the
play buttons are still inactive.

on (press) {
//Sound is not playing and has not been paused
if (playing!=true) {
	if (paused!=true) { 
	playing=true;
	paused=false;
	stopped=false;
	myConditionText2="Playing";
secondSound.start(0); 
//
} //closes paused!=true
//
//Sound has been paused
if (paused==true) { 
	playing=true; 
	paused=false; 
	stopped=false
	secondSound.start(myMusicPosition2,0); 
		myConditionText2="Playing";
_root.secondSound.onSoundComplete = function() { 
	secondSound.start();

	secondSound.addListener = function() {
	stopped=false;
	start=true;
}	
	
} //Closes function
} //Closes paused==true
//

//END
}//Closes playing!=true
//
}//Closes on press


Best Regards [email protected]
Was This Post Helpful? 0
  • +
  • -

#4 chinchang   User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 727
  • Joined: 22-December 08

Re: Activate play buttons when sounds complete playing

Posted 31 March 2011 - 12:53 AM

Can you explain the following code :

_root.secondSound.onSoundComplete = function() { 
	/* What are the following lines supposed to do ? */
        secondSound.start();

	secondSound.addListener = function() {
	stopped=false;
	start=true;
        }	
	
} //Closes function


Was This Post Helpful? 0
  • +
  • -

#5 [email protected]   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 23-March 11

Re: Activate play buttons when sounds complete playing

Posted 31 March 2011 - 11:06 AM

Hi

The code is part of a online tutorial I'm currently following -

How to Pause a Looping Sound Object
http://www.kennybell...html#index.html

This is the code the tutorial uses 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;
	myConditionText="Playing";
myMusic.start(0,999); 
//
} //closes paused!=true
//
//Sound has been paused
if (paused==true) { 
	playing=true; 
	paused=false; 
	stopped=false
	myMusic.start(myMusicPosition,0); 
		myConditionText="Playing";
_root.myMusic.onSoundComplete = function() { 
	myMusic.start(); 
} //Closes function
} //Closes paused==true
//
//END
}//Closes playing!=true
//
}//Closes on press


Regards [email protected]
Was This Post Helpful? 0
  • +
  • -

#6 chinchang   User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 727
  • Joined: 22-December 08

Re: Activate play buttons when sounds complete playing

Posted 01 April 2011 - 05:37 AM

What do you want to do when a sound completes ? Mention them in points.

_root.secondSound.onSoundComplete = function() { 
	/* What are the following lines supposed to do ? */
        secondSound.start();

	secondSound.addListener = function() {
	stopped=false;
	start=true;
        }	
	
} //Closes function


Your above code does nothing what you mentioned before.
Was This Post Helpful? 0
  • +
  • -

#7 [email protected]   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 23-March 11

Re: Activate play buttons when sounds complete playing

Posted 01 April 2011 - 11:39 AM

Hi
Sorry I thought that you meant those 2 lines in particular.

What I am trying to do!

Currenlty I have six sounds each with their own Play, Pause and Stop buttons.
The idea is that while each sound is playing a 20 second count down will play
(the length of each sound file) when the 20 seconds are up the count down will
disapear and a graphic will display telling the player what the sound was.
The player can stop start or pause the sound at any time during the 20 seconds.

My Problems!

Currently the Start button becomes active after the Stop button has been pressed.
So even if the sound is over the player still has to press the stop button before
either playing the same sound again or one of the others.
What I would like is the Start button to become active as soon as the sound comes to an end.
I have tried putting the stop button code inside the onSoundcomplete function
playing=false;
paused=false;
stopped=true;
_root.firstSound.stop(firstSoundMc);
myMusicPosition=0;

Which would seem to be the logical thing to do. With no success!


Problem 2

When I create my count down dynamic text field for the first sound everything is fine,
the 20 seconds count down, I can pause or stop the seconds while it plays.
I then try and duplicate this for the second sound, giving all instances and variables
different names. Now the second sound plays as the first one did, but the first doesn't.

Problem 3

I can't get the graphic that I want to display when the 20 seconds are up to go invisible
at start up. I can hide the seconds count down using _root.textHolder._visible = false;
but when I try the same thing for the graphic _root.image1._visible = false;
it still displays.

This is the full programme code supposing the game had 2 sounds

Code on first frame of main timeline

stop();
this.createEmptyMovieClip("textHolder", this.getNextHighestDepth());
textHolder.createTextField("tf_description", this.getNextHighestDepth(), 500, 300, 180, 100);
_root.textHolder._visible = false;
_root.image1._visible = false;


textHolder.tf_description.border = true;
textHolder.tf_description.borderColor = 0xffffff;
textHolder.tf_description.background = true;
textHolder.tf_description.backgroundColor = 0xF64600;
textHolder.tf_description.wordWrap = true;

var descFmt:TextFormat = new TextFormat ();
descFmt.size = 100;
descFmt.color = 0xffffff;
descFmt.leftMargin = 15;
descFmt.rightMargin = 15;
descFmt.font = "Arial";
descFmt.align = "center";

firstSound = new Sound(firstSoundMc);
firstSound.attachSound("sound1");
myMusicVolume=100;
firstSound.setVolume(myMusicVolume);
this.onEnterFrame = function () {
	if (stopped!=true) {
	textHolder.tf_description.text = _root.firstSound.position/1000;
    textHolder.tf_description.setTextFormat(descFmt);
}
}

secondSound = new Sound(secondSoundMc);
secondSound.attachSound("sound2");
myMusicVolume2=100;
secondSound.setVolume(myMusicVolume2);
this.onEnterFrame = function () {
	if (stopped!=true) {
	textHolder.tf_description.text = _root.secondSound.position/1000;
    textHolder.tf_description.setTextFormat(descFmt);
}
}


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); 
_root.press_play._visible = false;
_root.textHolder._visible = true;
//
} //closes paused!=true
//
//Sound has been paused
if (paused==true) { 
	playing=true; 
	paused=false; 
	stopped=false;
	firstSound.start(myMusicPosition,0); 
	_root.firstSound.onSoundComplete = function() {
	_root.textHolder._visible = false;
	_root.image1._visible = true;
}
//Closes function
} //Closes paused==true
//
//END
}//Closes playing!=true
//
}//Closes on 


Code on the pause button

on (press) {
//Pause Button
	if (pause!=true) {
	playing=false;
	paused=true;
	stopped=false
	myMusicPosition=_root.firstSound.position/1000;
	_root.firstSound.stop("sound1");
}
}


Code on the stop button

on (press) {
//Stop Button
	playing=false;
	paused=false;
	stopped=true;
	_root.firstSound.stop("sound1");
	myMusicPosition=0;	
}


Thank you for your help, it is much appreciated!
Was This Post Helpful? 0
  • +
  • -

#8 [email protected]   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 23-March 11

Re: Activate play buttons when sounds complete playing

Posted 05 April 2011 - 04:44 PM

Hi

I thought I would try and simplify things by placing a 2 frame movieclip called showgraphic
on the root timeline frame 1 empty, frame 2, labeled nextframe, containing graphic, both frames
have stop(); action.

I then added the following to my play button -

_root.firstSound.onSoundComplete = function(){
	_root.showgraphic.gotoAndStop("nextframe");
    } 


When played my count down plays, sound ends, and still nothing!

Anyone have any suggestions please!

Best regards [email protected]









View Post[email protected], on 01 April 2011 - 11:39 AM, said:

Hi
Sorry I thought that you meant those 2 lines in particular.

What I am trying to do!

Currenlty I have six sounds each with their own Play, Pause and Stop buttons.
The idea is that while each sound is playing a 20 second count down will play
(the length of each sound file) when the 20 seconds are up the count down will
disapear and a graphic will display telling the player what the sound was.
The player can stop start or pause the sound at any time during the 20 seconds.

My Problems!

Currently the Start button becomes active after the Stop button has been pressed.
So even if the sound is over the player still has to press the stop button before
either playing the same sound again or one of the others.
What I would like is the Start button to become active as soon as the sound comes to an end.
I have tried putting the stop button code inside the onSoundcomplete function
playing=false;
paused=false;
stopped=true;
_root.firstSound.stop(firstSoundMc);
myMusicPosition=0;

Which would seem to be the logical thing to do. With no success!


Problem 2

When I create my count down dynamic text field for the first sound everything is fine,
the 20 seconds count down, I can pause or stop the seconds while it plays.
I then try and duplicate this for the second sound, giving all instances and variables
different names. Now the second sound plays as the first one did, but the first doesn't.

Problem 3

I can't get the graphic that I want to display when the 20 seconds are up to go invisible
at start up. I can hide the seconds count down using _root.textHolder._visible = false;
but when I try the same thing for the graphic _root.image1._visible = false;
it still displays.

This is the full programme code supposing the game had 2 sounds

Code on first frame of main timeline

stop();
this.createEmptyMovieClip("textHolder", this.getNextHighestDepth());
textHolder.createTextField("tf_description", this.getNextHighestDepth(), 500, 300, 180, 100);
_root.textHolder._visible = false;
_root.image1._visible = false;


textHolder.tf_description.border = true;
textHolder.tf_description.borderColor = 0xffffff;
textHolder.tf_description.background = true;
textHolder.tf_description.backgroundColor = 0xF64600;
textHolder.tf_description.wordWrap = true;

var descFmt:TextFormat = new TextFormat ();
descFmt.size = 100;
descFmt.color = 0xffffff;
descFmt.leftMargin = 15;
descFmt.rightMargin = 15;
descFmt.font = "Arial";
descFmt.align = "center";

firstSound = new Sound(firstSoundMc);
firstSound.attachSound("sound1");
myMusicVolume=100;
firstSound.setVolume(myMusicVolume);
this.onEnterFrame = function () {
	if (stopped!=true) {
	textHolder.tf_description.text = _root.firstSound.position/1000;
    textHolder.tf_description.setTextFormat(descFmt);
}
}

secondSound = new Sound(secondSoundMc);
secondSound.attachSound("sound2");
myMusicVolume2=100;
secondSound.setVolume(myMusicVolume2);
this.onEnterFrame = function () {
	if (stopped!=true) {
	textHolder.tf_description.text = _root.secondSound.position/1000;
    textHolder.tf_description.setTextFormat(descFmt);
}
}


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); 
_root.press_play._visible = false;
_root.textHolder._visible = true;
//
} //closes paused!=true
//
//Sound has been paused
if (paused==true) { 
	playing=true; 
	paused=false; 
	stopped=false;
	firstSound.start(myMusicPosition,0); 
	_root.firstSound.onSoundComplete = function() {
	_root.textHolder._visible = false;
	_root.image1._visible = true;
}
//Closes function
} //Closes paused==true
//
//END
}//Closes playing!=true
//
}//Closes on 


Code on the pause button

on (press) {
//Pause Button
	if (pause!=true) {
	playing=false;
	paused=true;
	stopped=false
	myMusicPosition=_root.firstSound.position/1000;
	_root.firstSound.stop("sound1");
}
}


Code on the stop button

on (press) {
//Stop Button
	playing=false;
	paused=false;
	stopped=true;
	_root.firstSound.stop("sound1");
	myMusicPosition=0;	
}


Thank you for your help, it is much appreciated!

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1