Another quick tutorial about using embedded assets in Flash using Haxe and Flashdevelop.
This time we are embedding an mp3.
For some reason in FlashDevelop after adding an mp3 to your project you can’t add the mp3 to the library. I am unsure why this is. What this means is we can’t embed the mp3 in exactly the same way as we embed a bitmap
Luckly there is a work around. There is a utility program called SWFMill that can create SWF files based on an xml config file. It looks like FlashDevelop uses SWFMill behind the scenes to create it’s library. You can see this by looking in the obj folder for a flash project as there is an xml file in there and also in the FlashDevelop install location, it includes a version of SWFMill.
So the first step is to create a swf file that contains our target mp3 file. My example xml config looks like this.
After creating the config file we call SWFMill to build the swf file with our mp3 in it. The call looks like this.
swfmill.exe simple config.xml music.swf
After SWFMill has run you should get a music.swf file and it should be about the same file size as your mp3.
Now import the music.swf file into your FlashDevelop project.
Right click the music.swf file and select the add to library option.
Now we need to create a class for the music file. There is one thing to note here. If you want this music class to be in a package you must set it’s name attribute in the SWFMill config above to “packageName.AssetName” or else you will get an error 2068 invalid sound. Here is the code snippet to create the sound class.
Playing the music is now very easy.
Next build of FlashDevelop will support MP3 embedding as with bitmaps.
Cheers.
That is good to hear, it will make adding and removing mp3s from my project simpler.