【问题标题】:Using sound assets in Haxe在 Haxe 中使用声音资源
【发布时间】:2013-03-01 00:09:52
【问题描述】:

我在 Haxe 中播放声音资源时遇到问题。我可以使用swfmill 导入mp3 而不会出错:

<?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>

在我的Main.hx 中,我创建了一个名为Shoot 的类,它以与我用于.png 资源的相同方式扩展Movieclip。然后我使用这个类如下:

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

但是在运行时,当执行这段代码时,我得到了错误

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

我在我的 swf xml 文件或 haxe 代码中犯了什么明显的错误?如何进一步调试此错误?

【问题讨论】:

    标签: audio haxe swfmill


    【解决方案1】:

    我终于设法通过将库中的声音声明为 Sounds(而不是 MovieClips)来播放它们

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

    而且您不需要将它们添加到舞台上,只需播放即可:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      相关资源
      最近更新 更多