2011-03-29 48 views

回答

0

ExternalInterface.call可用於從一個 SWF和,反之亦然調用JavaScript ,ExternalInterface.addCallback可用於暴露的某些方法由 JavaScript調用

例如,在每個SWF,你可能有:

ExternalInterface.addCallback("externalStopAudio", stopAudio); 

// later.. 
function stopAudio():void { 
    // Code to stop audio 
    _audioStream.stop(); 
} 

function playAudio():void { 
    // tell JS to stop all audio 
    ExternalInterface.call("stopAllAudio"); 
    // play this players audio 
    _audioStream.play(); 
} 

然後在它是一個包含SWF文件的HTML部分JS:

<script> 
    // these references need to be actual pointers to the SWFs, this will vary 
    // depending on how you have it setup - might be SWFObject, Jquery, etc 
    var a = [swf1, swf2, swf3]; 

    // called by SWF 
    function stopAllAudio() { 
     // called to SWF 
     for(var i = 0; i < a.length; i++) { 
      a[i].externalStopAudio(); 
     } 
    } 

</script> 

根據安全設置/域放置,您可能需要以下條件:

在HTML:

<param name="allowScriptAccess" value="always" /> 

在SWF:

flash.system.Security.allowDomain(sourceDomain) 

參見:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#addCallback%28%29

0

您可以使用javascript與網頁進行通信,然後網頁可以與其他swf進行通信。

1

更完整的解決方案將使用LocalSharedObject:http://www.adobe.com/products/flashplayer/articles/lso/

在啓動時,SWF生成一個GUID,然後加載LSO,並綁定到一個該LSO的財產(如'當前活動GUID')。然後,無論用戶什麼時候玩,瑞士法郎都會向LSO寫信。這將通知所有的swfs音樂正在播放,不需要JavaScript。這也適用於所有標籤,所以如果swf在另一個標籤上播放,它將停止(另外,google和chrome使用相同的LSO,因此它可以跨瀏覽器使用:-))

相關問題