2009-08-18 47 views
2

對於當前的項目,我們使用SwfObject 2.2來嵌入Flash文件,而CRD大師們正在使用SwfAddress 2.3來創建SEO閃存善良。如果你在一個頁面上包含了這兩個庫,那麼在API中使用SwfObject回調的任何嘗試(http://code.google.com/p/swfobject/wiki/api)都會阻止SwfObject的加載。在這個例子中,你可以簡單地通過HTML註釋掉SwfAddress文件來切換。SwfAddress與SwfObject的「回調」參數衝突

對不起,我不能指向這兩個庫在我的代碼下面的絕對URL。

<head> 
    <title>SWFObject 2.2 dynamic embed with callback</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    <script type="text/javascript" src="swfobject.js"></script> 
    <script type="text/javascript" src="swfaddress.js"></script> 
    <script type="text/javascript"> 
    function outputStatus(e) { 
     alert("e.success = " + e.success +"\ne.id = "+ e.id +"\ne.ref = "+ e.ref); 
    } 
    var params = {}; 
    params.allowscriptaccess = "always"; 

    swfobject.embedSWF("http://www.bobbyvandersluis.com/swfobject/testsuite_2_2/test6.swf", "myContent1", "300", "120", "9.0.0", "expressInstall.swf", null, null); 
    swfobject.embedSWF("http://www.bobbyvandersluis.com/swfobject/testsuite_2_2/test6.swf", "myContent2", "300", "120", "9.0.0", "expressInstall.swf", null, params, null, outputStatus); 
    </script> 
</head> 

<body> 
    <div id="myContent1"> 
     <h1>Alternative content</h1> 
     <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p> 
    </div> 
    <div id="myContent2"> 
     <h1>Alternative content</h1> 
     <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p> 
    </div> 
</body> 

任何想法?提前致謝!

+0

對我來說,這解決了一個問題,其中SWFAddress.as externalChange事件沒有觸發(swf仍然正確嵌入) – user531694 2011-05-10 23:58:47

回答

2

這是一個艱難的。

快速回答:您需要將空的對象,而不是「空」爲Flash變量和屬性:(See my corrected demo code here

swfobject.embedSWF("http://www.bobbyvandersluis.com/swfobject/testsuite_2_2/test6.swf", "myContent1", "300", "120", "9.0.0", "expressInstall.swf", {}, {}); 
swfobject.embedSWF("http://www.bobbyvandersluis.com/swfobject/testsuite_2_2/test6.swf", "myContent2", "300", "120", "9.0.0", "expressInstall.swf", {}, params, {}, outputStatus); 

完整的答案:挖入SWFAddress源代碼,他們是重寫的SWFObject嵌入功能,所以他們可以注入自己的。要做到這一點,他們必須做的一件事是將你傳遞的所有參數傳遞給他們自己的功能。 「空」你傳遞的屬性,對象是在這裏的SWFAddress代碼導致錯誤:

var _s2e = swfobject.embedSWF; 
    swfobject.embedSWF = function() { 
    _args = arguments; 
    if (typeof _args[8] == UNDEFINED) 
     _args[8] = {}; 
    if (typeof _args[8].id == UNDEFINED) 
     _args[8].id = _args[1]; // <-- ERROR here when this parameter (attributes) is null. 
     _s2e.apply(this, _args); 
     _ref.addId(_args[8].id); 
    } 

的錯誤導致整個第二嵌入失敗。

+0

謝謝,那就是它:)我應該想到,因爲SwfObject也需要空對象。當我從Adobe文檔複製它時,我發現它會起作用。衛生署! – mummybot 2009-09-05 16:34:10

+0

+1。良好的舊的計算器,爲我節省了自2008年以來的時間。 – 2012-08-10 14:00:37