会员中心
用户名:    密码:    验证码:      免费注册会员

jquery手册   CSS2手册       请关注健康

CSSer > 客户端开发 > web多媒体设计 > SWFObject详解:Flash的检测和嵌入Javascript脚本

来源: 作者: 发布时间:2007-02-05
雅虎收藏夹 百度收藏 Google书签 Yahoo书签 新浪ViVi 搜狐网摘 365Key网摘 天极网摘 diglog 和讯网摘 POCO网摘 YouNote网摘 博拉网 天下图摘 Del.icio.us digg reddit spurl BlinkList blogmarks

官方地址:http://blog.deconcept.com/swfobject/
目前最新版本:SWFObject 1.3
下载地址:http://blog.deconcept.com/swfobject/#download

特点:

1、支持所有flash内置参数设置。且设置更简单方便。
2、内嵌flash player升级探测器,并提示升级。
3、完全通过XHTML 1.0 Strict验证。
4、可以解决IE升级对flash的影响,支持绝大部分浏览器版本。

使用方法:

1、首先下载上面的SWFObject.js文件,放到你的网页目录下。
2、调用js文件,在中加入<script type="text/javascript" src="swfobject.js"></script>

3、设置需要插入flash的htm代码:

<div id="flashcontent">
  This text is replaced by the Flash movie.
</div>


这里放上你想替换flash的文字。

4、在上面代码后添加flash的设置代码:

<script type="text/javascript">
   var so = new SWFObject("movie.swf", "mymovie", "200", "100", "7", "#336699");
   so.write("flashcontent");
</script>

上面SWFObject中的基本参数设置依次为:文件地址,ID,宽度,高度,flash版本,背景色。

可选参数有:

useExpressInstall: 快速升级flash player 值为ture/false;
quality:播放品质,默认为"high";
xiRedirectUrl:指定完成(useExpressInstall)快速升级player后的定向网址。
redirectUrl:指定flash player版本不正确的定向网址。
detectKey:flash检测的地址参数,默认为detectflash。如:要不检测flash,可以在网址后面加上?detectflash=false。

so.write("flashcontent");是把flash内容写到id="flashcontent"里。

Flash参数设置:

<script type="text/javascript">
   var so = new SWFObject("movie.swf", "mymovie", "200", "100%", "7", "#336699");
   so.addParam("quality", "low");
   so.addParam("wmode", "transparent");
   so.addParam("salign", "t");
   so.write("flashcontent");
</script>

更多的的参数请参照Macromedia的详细介绍:http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_12701

Flashvars变量设置:

<script type="text/javascript">
   var so = new SWFObject("movie.swf", "mymovie", "200", "100", "7", "#336699");
   so.addVariable("variable1", "value1");
   so.addVariable("variable2", "value2");
   so.addVariable("variable3", "value3");
   so.write("flashcontent");
</script>

这样设置后,所有的变量就马上传到flash的_root上了。

另外,SWFObject还提供了一个getQueryParamValue()函数来调用URL网址串的参数。
例如网址:http://www.example.com/page.html?variable1=value1&variable2=value2
你可以通过以下方法来把上面的参数传递给flash。

<script type="text/javascript">
   var so = new SWFObject("movie.swf", "mymovie", "200", "100", "7", "#336699");
   so.addVariable("variable1", getQueryParamValue("variable1"));
   so.addVariable("variable2", getQueryParamValue("variable2"));
   so.write("flashcontent");
</script>

同时,getQueryParamValue()还支持从location.hash读取变量。


Flash player的快速安装功能

SWFObject完全支持Flash Player的快速安装功能。通过在flash的第一帧添加一段AS代码就可以轻松达到检测用户Flash Player版本,并提示更新的功能。expressinstall.as代码如下:

#include "expressinstall.as"

// initialize the ExpressInstall object
var ExpressInstall = new ExpressInstall();

// if the user needs to upgrade, show the 'start upgrade' button
if (ExpressInstall.needsUpdate) {

// this is optional, you could also automatically start the
// upgrade by calling ExpressInstall.init() here instead of the following lines

// attach the custom upgrade message and center it
var upgradeMsg = attachMovie("upgradeMsg_src", "upgradeMsg", 1);
upgradeMsg._x = Stage.width / 2;
upgradeMsg._y = Stage.height / 2;

// attach the button actions that will start the ExpresInstall updater
upgradeMsg.upgradeBtn.onRelease = function() {
// the ExpressInstall.init() method is what kicks off the actual update
ExpressInstall.init();
}
// if expressinstall is invoked, stop the timeline.
stop();
}

<script type="text/javascript">
   var so = new SWFObject("movie.swf", "mymovie", "200", "100", "8", "#336699", true);
   so.setAttribute('xiRedirectUrl', 'http://www.example.com/upgradefinished.html'); // must be the absolute URL to your site
   so.write("flashcontent");
</script>

注意要把上面的AS放到主时间轴第一帧。并且这一帧上不要放任何其他内容。具体示例:
http://blog.deconcept.com/swfobject/expressinstall.html

 


相关文章

  • 全新的 Flash 9 一瞥

    Flash9的升级主要体现在 编程功能上。 Flash9 将与 photoshop cs3 的结合更加紧密,在导入psd文件的时候将方便很多 。 工

  • 关于透明图片覆盖flash的方法

    要求:绝对定位,而且要将flash透明底. /*把图片从文档流中拖出,然后可以用top,left,right,bottom来对图片的绝对定位*/ pos

  • Adobe Flash CS3蓄势待发

    因为前段时间Photoshop CS3 Beta的发布,业界掀起了关于Adobe CS3的狂热讨论,国外的博客、论坛里挤满了来自各国的设计师

  • FLASH与ASP通信入门教程

    ★LV类基础讲解 这里我主要围绕我的教程进行讲解,区别有些全盘灌输的教程,我将有真对性的着重讲此类的两个方法和一个事

  • MP3及LRC歌词同步显示卡拉OK播放器

    功能: 1、通过浏览来加载外部的mp3歌曲,可以加载一首,也可以加载多首歌曲。 2、同时加载相同文件名的 .lrc 格式歌词。

  • 涂鸦板数据压缩的思考

    ★这两天利用晚自习做了一个非常简易的涂鸦板,就是能画线条能保存重放的那种,其实这是我专门为火山之家开发的签名板。由

  • Flash360度全景

    Flash360度全景演示: http://www.csser.com/upimg/media/panorama.swf Flash360度全景源代码: http://www.csser.com/upi

  • Flash游戏开发常用函数代

    ■■■对象数组 比如要构建一个有很多属性的数组,简单的可以这样做: 2004 代码: var a:Array = new Array(); for (var