Danboy
February 16, 2003, 12:21pm
1
Hi folks,
I need a bit of help here - I’ve followed Kirupa’s tutorial at http://www.kirupa.com/developer/actionscript/sound.htm , and have attached this piece of code to my start button as it says:
on (release) {
kirupaSound = new Sound(this);
kirupaSound.attachSound(“coolsound”);
kirupaSound.start(0, 99);
}
Everything seems fine and dandy. and my sound loop starts playing. Just one question though - what actionscript do you use to turn the sound off?!
Any help would be greatly appreciated, and would perhaps delay the onset of a nervous breakdown! :crazy:
Cheers,
Dan
system
February 16, 2003, 2:49pm
3
I did, but it generated this error message:
Scene=Scene 1, Layer=stop, Frame=1: Line 1: Statement must appear within on handler
kirupaSound.stop();
As you’ve probably guessed, I’m extremely new to Actionscripting within Flash. All I want to do is start and stop a piece of music that I’ve written within my webpage - it starts okay, but it’s stopping it that’s been the problem!
Have a look at the page here - www.fletchermunsoneffect.co.uk/indexone.htm and you’ll see what I’m trying to do. The page isn’t completely finished - the rollovers and links don’t work yet, but you’ll get the basic idea.
Also, if you press play again, the music starts looping again over the original loop. How can I prevent this?
Thanks for your help,
Dan
system
February 16, 2003, 2:52pm
4
Scene=Scene 1, Layer=stop, Frame=1: Line 1: Statement must appear within on handler
kirupaSound.stop();
Well your adding the code to your button without an ‘on’ handler:
Play Button Actions:
on (release) {
kirupaSound = new Sound(this);
kirupaSound.attachSound(“coolsound”);
kirupaSound.start(0, 99);
}
Stop Button Actions:k
on (release) {
kirupaSound.stop();
}
system
February 16, 2003, 3:10pm
5
Here is a solution that would use ONE Button to play, and stop the sound…
kirupaSound = new Sound(this);
kirupaSound.attachSound(“coolsound”);
myButton.onPress = function() {//Change myButton to your button’s instance name
x++;
kirupaSound.start(0, 99);
if (x>1) {
kirupaSound.stop();
delete x;
}
};
Untested, because I have no flash on this pc, tell me how it goes. Please attach this code in your Frame Actions…
system
February 16, 2003, 4:04pm
6
h88, you’re a star.
I attached the code to the stop button and everything works fine. Thanks a million.
One more question and I promise I’ll leave you alone!
How would I prevent the sound starting again if the play button is pressed a second time before the stop button? Any ideas?
Thanks again,
Dan
system
February 16, 2003, 4:15pm
7
Hey, didn’t I answer your question in the above post…?
Anyways, you might want to use two buttons instead tho, if so, try:
kirupaSound = new Sound(this);
kirupaSound.attachSound(“coolsound”);
PlayButton.onPress = function() {
_global.x++;
kirupaSound.start(0, 99);
if (x>1) {
this.enabled = false
_root.StopButton.enabled = true;
}
};
StopButton.onPress = function() {
if (x>1) {
kirupaSound.stop();
this.enabled = false
_root.PlayButton.enabled = true;
}
};
system
February 16, 2003, 4:47pm
8
Oops! Sorry about that - it’s been a long day!
I’ve sorted it now thanks to you and also the Flash 5 tutorials on the ultrashock site (www.ultrashock.com ).
Cheers again,
Dan