【问题标题】:Is it possible to play/pause an .html object?是否可以播放/暂停 .html 对象?
【发布时间】:2014-12-22 02:53:33
【问题描述】:

我一直在尝试使用 javascript 向我的 html 对象添加播放/暂停功能,但按钮似乎不起作用,并且我在控制台中没有发现任何错误。

<object data="dice.html" width="550px" height="400px" id="Player" style="visibility: visible;">
  <param name="allowfullscreen" value="true">
  <param name="allowscriptaccess" value="always">
</object>
<p>
  <button id="play1">Play</button>
  <button id="play2">Pause</button>
</p>
<script type="text/JavaScript">
  document.getElementById('play1').onClick = function() {
    document.getElementById('Player').Play();
  }
  document.getElementById('play2').onClick = function() {
    document.getElementById('Player').Stop();
  }
</script>

我尝试在网上寻找解决方案,其中大多数只讨论 .swf 文件类型。是否可以播放/暂停 .html 对象? .html 文件是使用 Flash 发布的。

【问题讨论】:

    标签: javascript html flash


    【解决方案1】:

    实际上,当您将 Flash 项目导出为 html 文件时,它会创建一个已嵌入 swf 的 html 文件。

    因此,我认为通过 javascript 对其进行控制的最佳选择是直接将 swf 嵌入到您的 object 标签中。

    现在,即使在你的情况下似乎真的不合适
    要访问嵌入在object 中的html 文件,您应该使用contentDocumentproperty

    document.querySelector("object").contentDocument.getElementById("external_element").doStuff()
    

    【讨论】:

      【解决方案2】:

      您应该使用 SWFobject 之类的东西将 swf 本身嵌入到您的网页中。

      完成此操作后,您应该能够使用生成的对实际 swf 对象的引用来做您想做的事情。您可能需要使用 ExternalInterface 来做您想做的事情。

      【讨论】:

      • 问题是我的 Flash 文件中有多个场景,因此不会将所有场景合并到一个 .swf 中。我将留下 6 个 swf 文件,我无法使用 flash 合并它们。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 2022-08-11
      • 2015-03-20
      • 2011-06-06
      相关资源
      最近更新 更多