【问题标题】:Resize Flash with Javascript?用 Javascript 调整 Flash 大小?
【发布时间】:2011-05-22 11:39:35
【问题描述】:

我想知道是否可以使用 javascript 调整 Flash 的大小。我无法单独更改 flash 对象中的任何代码,我只能使用 html、javascript 和 php。

这是我目前发现的:

    var changeMe = document.getElementById("content_embed");
  changeMe.height = yy;
  changeMe.width = xx;
  if (navigator.userAgent.toLowerCase().indexOf("safari")!=-1) {
    var changemeObject = document.getElementById("content_object");
    changeMeObject.height = yy;
    changeMeObject.width = xx;
  }
}

Content Embed 是嵌入标签,content object 是flash 中的object 标签。这适用于chrome(可能还有firefox),但不适用于ie。 在 Internet Explorer 中出现错误:Unable to set value of the property 'height': object is null or undefined
这是我一直在使用的示例页面:http://futuregamespc.com/behind/Popup/ 任何人都可以帮忙吗?谢谢大家,是你们让这个网站变得很棒。

【问题讨论】:

  • 尝试使用 jquery 抽象出所有浏览器特定的代码。
  • futuregamespc.com/behind/Popup/index2.html 会这样做,但它在 chrome 或 Internet Explorer 中不起作用,而且很奇怪,它不会返回任何错误,只是不起作用。

标签: javascript flash internet-explorer


【解决方案1】:

是的,这是可能的。

但是,当您在您的网站中显示 Flash 时,请使用 swfobject

它是一个轻量级的 JavaScript 库 这允许您将 swf 集成到 跨浏览器友好的方式 网站。

下面给出的是对 swfobject 的调用示例

var flashvars = {};
var params = {};
var attributes = {};
var width="300";
var height="120";

swfobject.embedSWF("myContent.swf", "myContent", width, height, "9.0.0","expressInstall.swf", flashvars, params, attributes);

如您所见,heightwidth 传递的是参数。
Read swfobject documentation 了解更多详细信息。

更新:这里是 Adob​​e 网站本身的another good write up on using swfobject

【讨论】:

  • 我不确定这是否符合 op 正在寻找的动态标准。他想在将 swf 加载到 dom 后调整其大小。使用这个建议,他必须销毁并重新创建对象,如果它需要在调整大小时保持在同一个地方,这可能是一个问题
  • 感谢这正是我想要的。我可以将它用于所有 swf 文件,而无需进行太多更改。我想要一个可以保存 Flash 文件状态的解决方案,而且效果很好。
猜你喜欢
  • 2011-12-01
  • 1970-01-01
  • 2012-08-12
  • 1970-01-01
  • 2014-04-15
  • 1970-01-01
  • 2010-09-15
  • 2017-02-02
  • 1970-01-01
相关资源
最近更新 更多