SwfAddress与SwfObject的'callback'参数冲突

时间:2009-08-18 21:34:59

标签: javascript callback swfobject conflict swfaddress

对于当前项目,我们使用SwfObject 2.2嵌入Flash文件,CRD大师正在使用SwfAddress 2.3来创建SEO闪存优势。

事实证明,如果页面中包含两个库,那么在API(http://code.google.com/p/swfobject/wiki/api)中使用SwfObject回调的任何尝试都会阻止SwfObject加载。在示例中,您可以通过HTML注释掉SwfAddress文件来切换它。

很抱歉,我无法在下面的代码中指出这两个库的绝对网址。

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

有什么想法吗?提前谢谢!

1 个答案:

答案 0 :(得分:2)

这是一个艰难的。

快速回答:您需要为flashVars和属性传递空对象而不是“null”:(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嵌入功能,以便他们可以自己注入。他们要做的一件事就是将您传入的所有参数传递给他们自己的函数。您为属性对象传递的“null”导致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);
    }

错误导致整个第二次嵌入失败。