Be a Supporter!

Tell flash to load a sound

  • 574 Views
  • 15 Replies
New Topic Respond to this Topic
Whoisi
Whoisi
  • Member since: Mar. 9, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Tell flash to load a sound 2007-04-21 22:51:50 Reply

How 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.

Fion
Fion
  • Member since: Aug. 21, 2005
  • Offline.
Forum Stats
Member
Level 39
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:02:42 Reply

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);
}


.

BBS Signature
Ansel
Ansel
  • Member since: Sep. 2, 2006
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:03:12 Reply

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.


BBS Signature
Coaly
Coaly
  • Member since: Aug. 11, 2004
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:06:18 Reply

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


BBS Signature
Ansel
Ansel
  • Member since: Sep. 2, 2006
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:08:55 Reply

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.


BBS Signature
Fion
Fion
  • Member since: Aug. 21, 2005
  • Offline.
Forum Stats
Member
Level 39
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:09:38 Reply

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


.

BBS Signature
Whoisi
Whoisi
  • Member since: Mar. 9, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:10:02 Reply

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?

Fion
Fion
  • Member since: Aug. 21, 2005
  • Offline.
Forum Stats
Member
Level 39
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:15:06 Reply

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.


.

BBS Signature
Whoisi
Whoisi
  • Member since: Mar. 9, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:21:34 Reply

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?

InkyBoy
InkyBoy
  • Member since: Aug. 6, 2006
  • Offline.
Forum Stats
Member
Level 21
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:25:37 Reply

At 4/21/07 11:10 PM, Whoisi wrote: I'm getting an error:

Instance name...?

Coaly
Coaly
  • Member since: Aug. 11, 2004
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:26:45 Reply

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.


BBS Signature
Whoisi
Whoisi
  • Member since: Mar. 9, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:27:53 Reply

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.

Whoisi
Whoisi
  • Member since: Mar. 9, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Tell flash to load a sound 2007-04-21 23:49:47 Reply

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.

Coaly
Coaly
  • Member since: Aug. 11, 2004
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to Tell flash to load a sound 2007-04-22 00:04:43 Reply

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.


BBS Signature
Fion
Fion
  • Member since: Aug. 21, 2005
  • Offline.
Forum Stats
Member
Level 39
Blank Slate
Response to Tell flash to load a sound 2007-04-22 01:39:15 Reply

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.


.

BBS Signature
Whoisi
Whoisi
  • Member since: Mar. 9, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Tell flash to load a sound 2007-04-22 09:50:23 Reply

Great news! Everything works. The problem was in the file extension, though. Thanks for all your help!