The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsHow do I tell flash to load a sound when a button is pressed?
E.G: When I press the go button, I want a 'ding' sound to play.
Put the sound in your library and right click and go to linkage. Tick off export for actionscript and give it the linkage name beep. Then in the main timeline add this code:
Sound = new Sound(this);
Sound.attachSound("beep");
Then on the button have the code:
on (release) {
Sound.start(0,1);
}
.
put the sound in an MC, put the BUTTON in an MC, put a stop; action on the first frame of the MC and say whent he button is pressed play the movieclip.
At 4/21/07 11:02 PM, Fion wrote: Put the sound in your library and right click and go to linkage. Tick off export for actionscript and give it the linkage name beep. Then in the main timeline add this code:
Sound = new Sound(this);
Sound.attachSound("beep");
Then on the button have the code:
on (release) {
Sound.start(0,1);
}
Wow a truly helpful answer in the first reply, yeah don't listen to junky, script is the way to go. Just a small point, Sound.start() will do the same thing as Sound.start(0,1) and Sound.start(delay in miliseconds, number of loops).
:D
At 4/21/07 11:06 PM, Coaly wrote: Wow a truly helpful answer in the first reply, yeah don't listen to junky,
that makes me sad. besides, we posted at the same time. if i'd known he posted an answer, i woudnt've. my way is easier for the non-AS-inclined.
At 4/21/07 11:06 PM, Coaly wrote:
Just a small point, Sound.start() will do the same thing as Sound.start(0,1) and Sound.start(delay in miliseconds, number of loops).
D
Good to know. I didn't know .start() would work without parameters. Thanks! =D
.
I'm getting an error:
**Error** Clipboard actions:Line 2: The property being referenced does not have the static attribute.
Sound.attachSound("beep");
I opened linkage, pressed 'Export in action script, but I didn't see a 'Linkage name' box, so I put 'beep' in the identifier box.
Is something else wrong or am I just blind?
Sorry! I wrote the code on the forums not realising I called the sound Sound which is part of another script, change all the bits that say Sound to something like BeepSound or something.
.
I changed every part that said Sound to Beep sound also renaming the identifier 'Beep'.
Now, it shows no errors, however, the sound still fails to play.
Exact code I put in:
Timeline:
BeepSound = new BeepSound(this);
BeepSound.attachBeepSound("Beep");
Button:
on (release) {
BeepSound.start(0,1);
}
Where did I go wrong?
At 4/21/07 11:10 PM, Whoisi wrote: I'm getting an error:
Instance name...?
At 4/21/07 11:21 PM, Whoisi wrote:
Timeline:
BeepSound = new Sound(this);
BeepSound.attachSound("Beep");
Button:
on (release) {
_root.BeepSound.start(0,1);
}
Where did I go wrong?
that's the fixed code. Sound() is a constructor for a Sound object, BeepSound is the object name, and attachSound() is the method, not attachBeepSound(). Also since the object is on the main timeline, you need to use _root. to reach it.
At 4/21/07 11:25 PM, InkyBoy wrote:At 4/21/07 11:10 PM, Whoisi wrote: I'm getting an error:Instance name...?
You can't give sounds instance names. If you can I'm definitely missing something.
Either I am a complete idiot, or something's wrong with the code.
I'm Copied and pasted the code above: The Timeline part to the frame in which I want the sound to be played in, and the button part on the button.
My sound has the Identifier Beep.
I'm thinking the problem is that the file is a .aiff file. But since flash recognizes it, I'm not really sure.
At 4/21/07 11:49 PM, Whoisi wrote: I'm thinking the problem is that the file is a .aiff file. But since flash recognizes it, I'm not really sure.
well I've tried the same code with a wav file and it works, check everything again, the identifier would be the most likely mistake, maybe its the file, try to covert it or something.
Sorry that my corrections werent very clear I was in a rush. What Coaly said should work, just check to see that the identifier is correct, if it still doestly work after that to check if it's the file try using the same code on a wav or something.
.
Great news! Everything works. The problem was in the file extension, though. Thanks for all your help!