EDIT 2: swfmill has actually been updated for the first time in about 3 years (wav support included)! An official Windows binary and source code available here. If you’re a Windows user you can skip the stuff about compiling swfmill.

EDIT: Windows swfmill that (apparently) supports wav files available here (thanks rideforever). Just skip straight to working with swfml if you’re using these builds.

Why mxmlc can’t import wav (or any other lossless audio format) files I will never know. Mp3s suffer from timing/looping issues that are easily resolved by using wav files so I’ve always found a way to get my wav files into my swfs. Usually it’s by using the Flash IDE, but I refuse to involve it in my development process anymore.

Other solutions involve parsing wav files, generating swfs on-the-fly, or using Flash 10’s sound api. None really satisfied what I was looking for, compiling them directly into my AS3 code.

I’ve recently discovered a very good solution. It involves compiling a custom version of swfmill with support for wav files then using it to generate swf files. Since any resource inside a swf can be embedded into other swf files using mxmlc, I can then actually import a wav file.

Compiling swfmill

EDIT 2: Like I mentioned above, if you’re a Windows user you can skip this section. Also, if your favorite package manager has swfmill 0.3.0, you can just use that version instead.

This process is intended for Ubuntu, but it’s probably similar to the OSX version if you do the some extra research yourself. As for Windows, you’re on your own, unless you find a way to do it with cygwin.

First, make sure necessary build tools and libraries are available to compile swfmill. On Ubuntu these will do the trick (I think, be sure to comment if you find something is missing):

$ sudo apt-get install build-essential
$ sudo apt-get build-dep swfmill

Next, download the fork of swfmill located here. There’s a download link above the description. It’s a little more advanced than the version available on swfmill.org, in paticular it has support for wav files. Use the latest version of swfmill available here. The lastest version of swfmill will do the trick now. Get it here. Extract it to a folder and compile it.

$ ./autogen.sh
$ make

If anything goes wrong you might be missing some libraries or tools. Use this new new swfmill binary (it’s in the src folder) to compile the upcoming swfml files. Now you can create swf files with wav files in them, but they’re not in your main swf yet.

Using swfmill

This sample swfml file will create a swf file with a single wav file embedded inside (I personally recommend only having one wav file per swf file). Not all wav files will work. only PCM wav files with a frequency of 44100 Hz and below are allowed. Replace “wav_file_to_import” with the location of your wav file and compile.

$ swfmill simple examplesound.swfml examplesound.swf

As an added bonus, it will also play the wav file if you open the swf. Now you can embed the wav file in this swf into your main swf using the embed tag.

static private const ExampleSound:Class;

public function playSound():void {
  var sound:Sound = new ExampleSound() as Sound;
  sound.play(0, 1);

Hope that helps somebody, it’s been a thorn in my side for a long time.