【问题标题】:swfobject.embedSWF doesn't do anything. What am i missing?swfobject.embedSWF 不做任何事情。我错过了什么?
【发布时间】:2011-09-29 18:36:34
【问题描述】:

我正在尝试使用 swfObject 在我的网站上嵌入 Flash 视频播放器。这是我的代码的一些 sn-ps:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>

<script type="text/javascript">

if (typeof ARI == 'undefined')
{
     ARI = {};
}

ARI.InsertFlash = function()
{
    var flashvars = {};
    var parameters = {};
    parameters.quality = 'high';
    parameters.play = 'true';
    parameters.LOOP = 'false';
    parameters.wmode = 'transparent';
    parameters.allowScriptAccess='true';

    var attributes = {};

    attributes.id='ARIVID';

    swfobject.embedSWF("AS3MediaPlayer.swf","inlieu","720","405","9.0.0","",flashvars,parameters);
    }
</script>

...

<body>
<div class='inlieu'>
       <p> this will be replaced</p>
</div>
<button type='button' onclick='ARI.insertFlash();'>Insert</button>

这没有任何作用。我的按钮确实命中了正确的功能(请原谅页面上可能出现的任何 html 错误)。我已经用 div 测试过了。该函数本身会触发,但我的 div 没有被替换。我在这里想念什么?我想嵌入一个使用外部接口的 flash 对象,所以任何对我的问题的回答都会有帮助。此外,我希望它在用户按下按钮时触发,而不是在页面加载时触发,就像互联网上的大多数示例一样。

谢谢

阿里

【问题讨论】:

    标签: javascript html flash swfobject externalinterface


    【解决方案1】:

    SWFObject 需要目标元素上的 ID,您正在使用一个类。将class='inlieu' 更改为id='inlieu'

    此外,由于您在属性中指定了 ID,因此您的新对象将具有 ID ARIVID,并且不会继承 ID inlieu

    这个

    <body>
    <div id='inlieu'>
       <p> this will be replaced</p>
    </div>
    <button type='button' onclick='ARI.insertFlash();'>Insert</button>
    

    会变成这样

    <body>
    <object id="ARIVID" ... ></object>
    <button type='button' onclick='ARI.insertFlash();'>Insert</button>
    

    【讨论】:

      【解决方案2】:

      嗯,你正在从 http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js 加载 swfobject
      将文件放在与您的 swf/html 相同的域中,您的问题应该会消失。
      除了试图窃取带宽之外,您没有理由从 google 加载,如果他们决定用新的东西更新该代码库,这可能会导致您的版本问题。

      此外,您应该按照您的说明在 onLoad 或单击按钮时调用该函数。您发布的代码在页面完成加载之前正在运行,并且可能尚未加载来自谷歌的 javascript 文件。
      您可以将此代码放在 embed 语句之前进行测试。

      alert( swfobject );
      

      【讨论】:

      • 从 googleapis.com 加载没问题,不会影响任何事情。
      • 从中心位置加载库不一定是“窃取带宽”,并且具有许多优势。它不会导致版本问题,因为 lib 在 URL 中是版本化的。您不需要在 onLoad 中调用 swfobject,因为 swfobject 默认以这种方式工作。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多