2012-07-05 49 views
1

我在HTML5游戏中为我的音频使用Buzz库。交叉菜单,无需音乐停止,我加载每个菜单的iframe和音乐从主页推出:buzz.all()。静音()在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(); 

什么也没有发生。我猜测iframe中的buzz变量和主页中的buzz变量不一样。我如何访问主页的buzz,以便所有音乐都能正确静音?

如果需要,我会很乐意给出更多细节。

回答

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) 
+0

也可以'window.parent.contentWindow.buzz.all()静音();' – wizzard0 2012-07-05 16:39:20

+0

如果你是在同一个域中这工作得很好。不幸的是,我在本地工作,所以我遇到了一些安全错误。切换到postMessage()msg主窗口停止音乐。 – 2012-07-05 17:32:18