Using sound assets in Haxe

928 views Asked by At

I am having trouble playing sound assets in Haxe. I am able to import mp3s with swfmill without error:

<?xml version="1.0" encoding="utf-8" ?>
<movie width="100" height="100">    
    <frame>     
        <library>
            ... other resources ...
            <sound id="Shoot" import="shoot.mp3"/>
        </library>
    </frame>    
</movie>

In my Main.hx, I created a class called Shoot which extends Movieclip in the same way I used for my .png resources. Then I use this class as follows:

var sound:MovieClip = new Shoot();
stage.addChild(sound);
sound.play();

But at runtime, when this code is executed, I get the error

"Error #2136: The SWF File <project swf> contains invalid data".

Any obvious mistakes I'm making in my swf xml file or haxe code? How can I debug this error further?

1

There are 1 answers

0
andrechalom On

I finally managed to play sounds from the library by declaring them as Sounds (instead of MovieClips)

class Shoot extends flash.media.Sound {public function new() { super(); }}

and you don't need to add them to the stage, just play it:

var shoot : flash.media.Sound = new Shoot();
shoot.play();