beans
beans

Reputation: 1765

Embed a wav as3

How can I embed a wav into as3/flash builder?

I have:

[Embed(source="assets/sounds/claps.wav")]
public var testSound:Class;
private var blahsound:Sound = Sound(new testSound());

But no luck...

Upvotes: 2

Views: 2312

Answers (3)

Benny Bottema
Benny Bottema

Reputation: 11493

You can try the open source library, as3wavsound (AWS). It supports embedding .wav files and playing them natively.

Upvotes: 0

divillysausages
divillysausages

Reputation: 8033

It's possible, but hacky. As @32bitkid said, FP doesn't directly support loading sound files other than mp3. The solution is to load the wav as a ByteArray, construct a SWF in memory (as using the Flash IDE, you can add wav files), then access the Sound object from this SWF.

Check out http://richapps.de/?p=97

Upvotes: 0

J. Holmes
J. Holmes

Reputation: 18546

You can't. Well, not directly.

Although there are various sound file formats used to encode digital audio, ActionScript 3.0, Flash Player and AIR support sound files that are stored in the mp3 format. They cannot directly load or play sound files in other formats like WAV or AIFF.

You either need to convert it to an mp3 before embedding it. Or embed it as a ByteArray, and then try to use SampleDataEvent.SAMPLE_DATA to fill the sound buffer manually with the bytes from the wav file, but you are going to have to do some finagling.

Upvotes: 3

Related Questions