View Full Version : Flash MX soundobject help
Danboy
February 16th, 2003, 07:21 AM
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
h88
February 16th, 2003, 09:32 AM
did you try:
kirupaSound.stop();
Danboy
February 16th, 2003, 09:49 AM
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
h88
February 16th, 2003, 09:52 AM
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();
}
h88
February 16th, 2003, 10:10 AM
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...
Danboy
February 16th, 2003, 11:04 AM
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! :smirk:
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
h88
February 16th, 2003, 11:15 AM
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;
}
};
Danboy
February 16th, 2003, 11:47 AM
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
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.