Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Audio on/off button 1

Status
Not open for further replies.

Jennyucf

Instructor
Jun 22, 2001
215
US
Hi, there

I am making an audio on/off button. When the audio is on again, I want the sound continue to play, instead of starting from the beginning again....Would you tell me where I can find a sample, or how I can achieve this?

Thanks for all the great help from this forum...It's just so supportive.

Cheers
Jenny
 
Everything you ever wanted to know about sound but were afraid to ask!

Regards,

oldman3.gif
 
Hi, thank you for the quick reply!!
I browsed the website, and it is very cool! But I found that all the buttons are separate: on is one, and off is another...Do you know where I can find the toggle button to control the audio?

Many many thanks!
 
Pause Button:
on(release){
mySound.stop();
}
Resume Button:
on(release){
var x = mySound.position/100;
mySound.start(x);
}

Sound.position returns number of milliseconds the sound clip has been playing.
Sound.start - you can pass an optional parameter telling it where to start the sound clip from (in seconds)

to toggle sound
 
This is better than the first off the top of my head solution..knew i had it somewhere

//Frame Action

s1=new Sound();
s1.attachSound("whatever");//or loadsound if external
s1.start();
mark1 = (getTimer()/1000);

two buttons one to pause and one to resume :

//to pause
on (release) {
s1.stop();
mark2 = (getTimer()/1000);
}

//to resume
on (release) {
soOld = offset;
offset = (mark2-mark1)+soOld;
s1.start(offset, 0);
mark1 = (getTimer()/1000);
}


To make button with - click=pasue and click again=play one button alternate action :

on (press) {
if (_root.Pause) {
_root.Pause = false;
soOld = offset;
offset = (mark2-mark1)+soOld;
s1.start(offset, 0);
mark1 = (getTimer()/1000);
} else {
_root.Pause = true;
s1.stop();
mark2 = (getTimer()/1000);
}
}
 
wow, this is very impressive!! Thank you so so much. I will try that out!

Cheers
Jenny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top