Swfobject 和 MooTools:动态影片高度

发布于 2024-08-11 04:49:05 字数 1960 浏览 5 评论 0原文

问候。

我正在为 Flash-HTML 混合网站开发动画主页,出于标准考虑,我的解决方案被证明很困难。我不是 Javascript 专业人士,因此非常感谢您的帮助!

概要如下:

对于 Flash 用户,HTML 页面会加载一个可变高度的 AS3 Flash 影片,该影片将以 556 像素高开始,完成其动画序列后,通过 Actionscript + JavaScript 补间到 < strong>250 像素高。

为了开始这个电影序列 - (左下) - 我尝试通过 MooTools 设置 Flash 电影的初始高度,因此如果用户没有启用 Flash 或 Javascript,他们将查看高度较短的图像区域,其中显示了替代图像内容和 HTML 内容(右下)

Element.setStyle 将高度设置得很好,直到 swfObject 运行为止,此时影片会崩溃,因为我没有通过 CSS 指定高度。如果用户没有Flash,则默认为静态图像的高度。

所以这是我的问题:有谁知道当宽度/高度设置为 100% 时如何动态地将高度变量传递给 swfobject ?我是否会无缘无故地自杀尝试使用两个页面高度?

图像序列:
左 - 下面带有 HTML 导航的初始 Flash 影片
右 - 在序列末尾调整影片大小,并使用 HTML 导航和导航下面的内容,看起来与无 Flash 版本(静态图像)相同

alt文本http://client.deicreative.com/op/images/twopages.jpg

                                           ^^ should land here for users w/o Flash

<script type="text/javascript">
  <!--
  window.addEvent('domready', function() {
     $('flashContent').setStyle('height', 556); // sets height for initial movie
     $('homeContent').setStyle('display', 'none'); // hides homepage text + photos below
     doSwfObject(); // attempting to start swfObject after setStyle is done
  });
  function resizePage(h) { // to be called from AS3
   var tweenObj = new Fx.Tween('flashContent');
   tweenObj.start('height', h);
  }
  function doSwfObject(){
   var flashvars = {};
   var params = { scale: "noScale" };
      var attributes = { id: "flashContent", name: "flashContent" };
   swfobject.embedSWF("swf/homeMovie.swf", "flashContent", "100%", "100%", "9.0.0", false, flashvars, params, attributes);
   alert(document.getElementById('flashContent').style.height); 
   // alerts & shows correct height, but page collapses after hitting 'ok'
  }
  //-->
</script>

Greetings.

I am developing an animated homepage for a Flash-HTML hybrid website, and for the sake of standards, my solution is proving difficult. I am not a Javascript pro, so any help is appreciated!

Here is the run-down:

For Flash users, HTML page loads a variable-height AS3 Flash movie that will start at 556 pixels high, and after finishing its animation sequence, tween via Actionscript + JavaScript to 250 pixels high.

To kick off this movie sequence -- (below-left) -- I am attempting to set the initial height of the Flash movie via MooTools, so if users do not have Flash or Javascript enabled, they will see the shorter-height image area with alternative image content and HTML content revealed (below-right).

Element.setStyle sets the height just fine until swfObject runs, at which point the movie collapses since I am not specifying a height via CSS. If users do not have Flash, it defaults to the height of a static image.

So here is my question: Does anyone know how to dynamically pass a height variable to swfobject when it is set up to width/height @ 100%? Am I killing myself for no reason trying to work with two page heights?

Image Sequence:
Left - Initial Flash movie with HTML navigation below
Right - Resized movie at the end of the sequence with HTML nav & content below, looks the same as no-Flash version (static image)

alt text http://client.deicreative.com/op/images/twopages.jpg

                                           ^^ should land here for users w/o Flash

<script type="text/javascript">
  <!--
  window.addEvent('domready', function() {
     $('flashContent').setStyle('height', 556); // sets height for initial movie
     $('homeContent').setStyle('display', 'none'); // hides homepage text + photos below
     doSwfObject(); // attempting to start swfObject after setStyle is done
  });
  function resizePage(h) { // to be called from AS3
   var tweenObj = new Fx.Tween('flashContent');
   tweenObj.start('height', h);
  }
  function doSwfObject(){
   var flashvars = {};
   var params = { scale: "noScale" };
      var attributes = { id: "flashContent", name: "flashContent" };
   swfobject.embedSWF("swf/homeMovie.swf", "flashContent", "100%", "100%", "9.0.0", false, flashvars, params, attributes);
   alert(document.getElementById('flashContent').style.height); 
   // alerts & shows correct height, but page collapses after hitting 'ok'
  }
  //-->
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

待"谢繁草 2024-08-18 04:49:05

最简单的解决方案是将 SWF 嵌入到包装 DIV 中。将 SWF 设置为包装器 DIV 的 100% 宽度/高度,然后使用 JS 调整包装器 DIV 的大小,而不是 的大小。本身。这样就少了很多麻烦。

由于 SWFObject 2 将目标 DIV 替换为对象,因此您需要在标记中添加一个额外的 div

<div id="wrapper">
   <div id="flashcontent"></div>
</div>

<div id="wrapper">
   <object id="flashcontent" width="100%" height="100%" (etc.) ></object>
</div>

The simplest solution is to embed your SWF in a wrapper DIV. Set the SWF to 100% width/height of the wrapper DIV, then use JS to resize the wrapper DIV, not the <object> itself. Less buggy that way.

Since SWFObject 2 replaces the target DIV with the object, you'll need an additional div in your markup:

<div id="wrapper">
   <div id="flashcontent"></div>
</div>

becomes

<div id="wrapper">
   <object id="flashcontent" width="100%" height="100%" (etc.) ></object>
</div>
因为看清所以看轻 2024-08-18 04:49:05

我认为在这里发布一些东西可以帮助我思考问题——这样做之后,答案就变得更加清晰了。所以这是我为后来偶然发现这个问题的人提供的解决方案。

为了将 Flash 影片的高度设置为初始较高状态,同时为非 Flash 用户保留较短的高度(请参见上图),我使用 JavaScript,就像在序列完成后调整影片高度一样。结果类似于报纸网站上的下推式广告。

在 AS3 中,预加载完成后,我告诉 Javascript 补间 Flash 影片容器的高度(显然是简单的——没有预加载代码):

package {
   import flash.display.MovieClip;
   import flash.display.StageAlign;
   import flash.display.StageScaleMode;
   import flash.external.ExternalInterface;

    public class HomeMovie extends MovieClip {

       private var stageHeight:uint;

       public function HomeMovie(){

           this.stage.scaleMode = StageScaleMode.NO_SCALE;
           this.stage.align = StageAlign.TOP_LEFT;

           stageHeight = 556;
           // Tell javascript the stage needs resizing.
           if (ExternalInterface.available) {
           ExternalInterface.call("resizePage", stageHeight);
           }
        }
    }

}

在 JavaScript 中(通过 MooTools):

<script type="text/javascript">
<!--
window.addEvent('domready', function() { // hide content on home-page below movie
   $('homeContent').setStyle('display', 'none');
});
function resizePage(h) {
    var tweenObj = new Fx.Tween('flashContent', {
        property:'height',
        duration:500,
        transition:Fx.Transitions.Quad.easeOut
    });
    tweenObj.start(h);
}
//-->
</script>

我可能会更进一步并检查在隐藏主页内容之前先对Flash进行隐藏,这样如果用户有Javascript但没有Flash就不会发生这种情况。再说一遍,这都是为了标准。

I think the act of posting something on here helps me think through the problem -- after doing so, the answer became more clear. So here is my solution for anyone who stumbles across this later.

To animate the Flash movie's height to its initial, taller state while preserving shorter height for non-Flash users (see images above), I use JavaScript the same way I would to tween the movie's height once sequence is complete. The result resembles a push-down ad on a newspaper website.

In AS3, after preloading is done, I tell Javascript to tween the height of the flash movie container (simplified, obviously -- there is no preloading code):

package {
   import flash.display.MovieClip;
   import flash.display.StageAlign;
   import flash.display.StageScaleMode;
   import flash.external.ExternalInterface;

    public class HomeMovie extends MovieClip {

       private var stageHeight:uint;

       public function HomeMovie(){

           this.stage.scaleMode = StageScaleMode.NO_SCALE;
           this.stage.align = StageAlign.TOP_LEFT;

           stageHeight = 556;
           // Tell javascript the stage needs resizing.
           if (ExternalInterface.available) {
           ExternalInterface.call("resizePage", stageHeight);
           }
        }
    }

}

In JavaScript (via MooTools):

<script type="text/javascript">
<!--
window.addEvent('domready', function() { // hide content on home-page below movie
   $('homeContent').setStyle('display', 'none');
});
function resizePage(h) {
    var tweenObj = new Fx.Tween('flashContent', {
        property:'height',
        duration:500,
        transition:Fx.Transitions.Quad.easeOut
    });
    tweenObj.start(h);
}
//-->
</script>

I will probably take it one step further and check for Flash before hiding the home-page content, so that it will not occur if the user has Javascript but not Flash. Again, this is all for the sake of standards.

花开半夏魅人心 2024-08-18 04:49:05

您是否尝试过SWFForceSize?它是一个 SWFObject 插件,可以帮助您。即使您不使用它,您也可以查看源代码以了解它们是如何工作的。

Have you tryed SWFForceSize? It's an SWFObject addon and it could help you. Even if you don't use it, you could take a look at the source code to see how they do things.

清风无影 2024-08-18 04:49:05

顺便说一句,在使用 Mootools 时,您不需要 SWF 对象,因为它有一个名为 Swiff 的调用,它可以完成 SWFObject 所做的所有事情,甚至还有一些! :D

Btw you don't need SWF object when using Mootools as it has a call called Swiff that does everything SWFObject does and then some! :D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文