(Download)
Oh, to embed sound with swfmill and haXe for Flash 9. (Project Page)
After messing around with the URLRequest and Sound objects one would follow up with "OK, now how do I embed sound resources into the SWF itself?".
Oh boy.
The direction you get pointed to for making embedded resources for haXe is the swfmill project. It seems like it gets a lot of use but event the front page warns that the software is "pretty stable". Fortunately the author has recently put in sound support for building a SWF library. I had put in the:
<sound id="sfx" import="sfx.mp3"/>
That executed the:
swfmill simple library.xml library.swf
And it all worked. Now that it seemed that the MP3 was embedded into the SWF library I wanted to load it in Main.hx. All of the references to do that looked like this.
media.attachSound("id");
Which had been obsoleted in Flash 9. Not deprecated, obsoleted. So not there was the mystery of how to load the thing. It turns out that in Flash 9 the id of the sound object is also a derived class name in which you do something to the effect of:
var snd:Sound = new id();
In AS3 but that was not working in haXe. After a while of research and running down the wrong paths of adding a class attribute to the sound tag in swfmill and trying to Type.createInstance(Type.resolveClass(classname), []) I finally found out from this thread and looking at create_resource.rb you have to do this little number.
library.xml
<sound id="SndClass" import="sfx.mp3"/>
Main.hx
class SndClass extends flash.media.Sound {}
...
var sound : flash.media.Sound = new SndClass();
And that works. How? Not sure. But not everything behaves as it should. You actually have to set the start position when you play() the clip "before" 0.
sound.play(-400);
So there are some issues but it does work... sort of.
