1

我在 HTML5 游戏中为我的音频使用 Buzz 库。为了在不停止音乐的情况下跨菜单,我将每个菜单加载到 iframe 中,然后从主页启动音乐:

<body style="overflow: hidden">
    <iframe id="MainFrame" src="./mainmenu.html" 
     frameborder=0 seamless="seamless" class="mainframe"></iframe>

    <script>
        window.onload = function() {
            playLoop('audio/menumusic.mp3');
        }
</script>
</body>

var playLoop = function(name)
{
    sound = new buzz.sound(name, {preload: true, loop: true});
    sound.play();
    setInitialSoundState(sound);
    loops.add(sound);
}

事情是我希望能够切换/更改 iframe 中加载的页面中的音乐。但每当我使用

buzz.all().mute();

没发生什么事。我猜buzziframe 中的buzz变量和主页中的变量不一样。如何访问主页buzz以使所有音乐正确静音?

如果需要,我很乐意提供更多细节。

4

1 回答 1

1

试试这个:

window.parent.buzz.all().mute();
// window.parent references an iframe's parent window
// or the current window if the call is made from a regular page (i.e. not in an iframe)
于 2012-07-05T16:37:52.397 回答