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.

[Embed(source='examplesound.swf#importedsound')]
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.

9 Responses to “How to compile wav files into a swf”

  1. Rideforever Says:

    I would be very grateful for a copy of the windows binary as I don’t have the facility to compile the swfmill source … thanks ?

  2. Max Says:

    Rideforever: I’m sorry, I’m not really sure how to compile it on Windows.

    But. Try installing cygwin, then compiling it under a cygwin shell. This might work, assuming cygwin can download the libraries you need. This might be a little confusing, but it could work. Good luck.

  3. ActionCat Says:

    It’s completely ridiculous that mxmlc can’t import non-mp3 sounds.

    I’m stuck on Windows but at least I’m glad someone somewhere has found a solution. If either mxmlc would support wavs or sound editors would export to mp3 without adding silence to clips, my toolchain would be complete.

    Waiting in vain…

  4. Max Says:

    ActionCat: No use, mp3s appear to require this sound gap. I’ve seen solutions, but nothing that actually worked for me.

    EDIT: Except efficient use of lame’s –nogap feature.

  5. rideforever Says:

    The Windows binary for swmill with wav support is available … from the OSFlash swfmill mailing list (Daniel Cassidy on there is doing the updates)

  6. Laemeur Says:

    Ah, thank you so much for posting this, along with the link to the Windows binary of swfmill. Totally made my morning!

  7. Anonymous Says:

    Stupid asshole removed his swfmill fork repo. Thanks for a big fucking runaround waste of my precious time. Goddamn, I fucking hate Linux neckbeards

  8. Max Says:

    Anonymous: No worries, the official version of swfmill now includes support for the things in the fork. Presumably that’s why it was taken down.

    That’s why I mentioned the new version, right there at the top of the post.

  9. mchnzr Says:

    Thank you, this is super helpful! Worked perfectly for me on OSX.

Leave a Reply