swfobject.js 简介

来源:互联网 发布:github java 项目 编辑:程序博客网 时间:2024/06/08 14:18

swfobject是什么?
有些朋友可能可能并不熟悉它,但是如果你玩过flash,我想应该不会陌生。 

SWFObject是一个用于在HTML中方便插入Adobe Flash媒体资源(*.swf文件)的JavaScript模块。它能够避免您的 HTML、XHTML中出现object、embed等非标准标签,从而符合更加标准。

如果你现在需要急于了解如何使用它,那么你可以看看我下面的简短的介绍,相信能够帮助到您。

第一步,你可以去到http://code.google.com/p/swfobject/downloads/detail?name=swfobject_2_2.zip下载到它。

第二步,学会如何使用。

swfobject就是为我们提供更好更简单的方法将swf嵌入到html中,它给出两种方法让我们去做这事。

方法一:静态的插入

1. 使用object的标签插入swf

2. 在html的head内加入我们下载下来swfobject.js: <scripttype="text/javascript"src="swfobject.js"></script>

3. 使用swfobject提供的接口来关联swf

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">  <head>    <title>SWFObject - step 3</title>    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />    <script type="text/javascript" src="swfobject.js"></script>    <script type="text/javascript">    swfobject.registerObject("myId", "9.0.115", "expressInstall.swf");    </script>  </head>  <body>    <div>      <object id="myId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="780" height="420">        <param name="movie" value="test.swf" />        <!--[if !IE]>-->        <object type="application/x-shockwave-flash" data="test.swf" width="780" height="420">        <!--<![endif]-->          <p>Alternative content</p>        <!--[if !IE]>-->        </object>        <!--<![endif]-->      </object>    </div>  </body></html>


方法二:动态的插入
1. 给出div用来装载swf文件

<div id="myContent">      <p>Alternative content</p></div>


 

2. 在html的head内加入我们下载下来swfobject.js: <scripttype="text/javascript"src="swfobject.js"></script>

3. 使用swfobject提供的接口来关联swf

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">  <head>    <title>SWFObject dynamic embed - step 3</title>    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />    <script type="text/javascript" src="swfobject.js"></script>        <script type="text/javascript">    swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");    </script>  </head>  <body>    <div id="myContent">      <p>Alternative content</p>    </div>  </body></html>


当然swfobject还提供了一些额外的参数可以赋给swf文件。如:

var flashvars ={};var params ={};var attributes ={};
swfobject.embedSWF("myContent.swf","myContent","300","120","9.0.0","expressInstall.swf", flashvars, params, attributes);
这些我们都可以在需要的时候添加。
希望能够为所需要的朋友提供一点帮助。

 

0 0