swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes)有5个必须的参数和4个可选的参数:
- swfUrl(String,必须的)指定SWF的URL。
- id(String,必须的)指定将会被Flash内容替换的HTML元素(包含你的替换内容)的id。
- width(String,必须的)指定SWF的宽。
- height(String,必须的)指定SWF的高。
- version(String,必须的)指定你发布的SWF对应的Flash Player版本(格式为:major.minor.release)。
- expressInstallSwfurl(String,可选的)指定express install SWF的URL并激活Adobe express install [ http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75 ]。
- flashvars(String,可选的)用name:value对指定你的flashvars。
- params(String,可选的)用name:value对指定你的嵌套object元素的params。
- attributes(String,可选的)用name:value对指定object的属性。
例如:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("myflash.swf", "myflash", "300", "120", "9.0.0");
swfobject.embedSWF("myflash.swf", "myflash", "300", "120", "9.0.0", null, null, {wmode: ‘transparent’});
</script>
<div id="myflash">这里是当flash不能正常显示时显示的内容</div>
怎样配置你的Flash内容?
你可以为你的object元素添加下面这些常用的可选属性(attributes)[ http://www.w3schools.com/tags/tag_object.asp ]:
- id
- name
- styleclass(不使用class,因为class也是ECMA4的保留关键字)
- align
你可以使用下面这些专用于Flash的可选param元素[ http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_12701 ]:
- play
- loop
- menu
- quality
- scale
- salign
- wmode
- bgcolor
- base
- swliveconnect
- flahvars
- devicefont [ http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_13331 ]
- allowscriptaccess [ http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_16494 ]
- seamlesstabbing [ http://www.adobe.com/support/documentation/en/flashplayer/7/releasenotes.html ]
- allowfullscreen [ http://www.adobe.com/devnet/flashplayer/articles/full_screen_mode.html ]
- allownetworking [ http://livedocs.adobe.com/flash/9.0/main/00001079.html ]
怎样用JavaScript对象来定义你的flashvars、params和attributes?
你最好用对象的字面量(Object literal notation)来定义JavaScrpt对象,例如这样:
var flashvars = {} ;
var params = {} ;
var attributes = {} ;
swfobject . embedSWF ( “ myContent.swf “ , “ myContent “ , “ 300 “ , “ 120 “ , “ 9.0.0 “ , “ expressInstall.swf “ , flashvars , params , attributes ) ;
< / script>
你可以在定义对象的时候添加你的name:value对(注意:请确保不要再对象中的最后一个name:value对后面加上逗号):
var flashvars = {
name1 : “ hello “ ,
name2 : “ world “ ,
name3 : “ foobar “
} ;
var params = {
menu : “ false “
} ;
var attributes = {
id : “ myDynamicContent “ ,
name : “ myDynamicContent “
} ;
swfobject . embedSWF ( “ myContent.swf “ , “ myContent “ , “ 300 “ , “ 120 “ , “ 9.0.0 “ , “ expressInstall.swf “ , flashvars , params , attributes ) ;
< / script>
或者在对象创建之后用点号添加属性(properties)和值:
var flashvars = {} ;
flashvars . name1 = “ hello “ ;
flashvars . name2 = “ world “ ;
flashvars . name3 = “ foobar “ ;
var params = {} ;
params . menu = “ false “ ;
var attributes = {} ;
attributes . id = “ myDynamicContent “ ;
attributes . name = “ myDynamicContent “ ;
swfobject . embedSWF ( “ myContent.swf “ , “ myContent “ , “ 300 “ , “ 120 “ , “ 9.0.0 “ , “ expressInstall.swf “ , flashvars , params , attributes ) ;
< / script>
上面的代码也可以这样写(为那些喜欢俏皮话的顽固脚本程序员准备的不易读的简写版本(the less readable shorthand version for the die-hard scripter who love one-liners)):
swfobject . embedSWF ( “ myContent.swf “ , “ myContent “ , “ 300 “ , “ 120 “ , “ 9.0.0 “ , “ expressInstall.swf “ , { name1 : “ hello “ , name2 : “ world “ , name3 : “ foobar “ } , { menu : “ false “ } , { id : “ myDynamicContent “ , name : “ myDynamicContent “ }) ;
< / script>
如果你不想使用一个参数,你可以将它定义为false或者一个空对象:
var flashvars = false ;
var params = {} ;
var attributes = {
id : “ myDynamicContent “ ,
name : “ myDynamicContent “
} ;
swfobject . embedSWF ( “ myContent.swf “ , “ myContent “ , “ 300 “ , “ 120 “ , “ 9.0.0 “ , “ expressInstall.swf “ , flashvars , params , attributes ) ;
< / script>
flashvars对象是一个为了增加易用性而设计的作为快捷方式的参数,所以你可以先忽略它,然后在params对象中指定你的flashvars:
var flashvars = false ;
var params = {
menu : “ false “ ,
flashvars : “ name1=hello&name2=world&name3=foobar “
} ;
var attributes = {
id : “ myDynamicContent “ ,
name : “ myDynamicContent “
} ;
swfobject . embedSWF ( “ myContent.swf “ , “ myContent “ , “ 300 “ , “ 120 “ , “ 9.0.0 “ , “ expressInstall.swf “ , flashvars , params , attributes ) ;
< / script>
提示:使用SWFObject 2.0 HTML和JavaScript代码生成器(SWFObject 2.0 HTML and JavaScript generator)来帮助你创建代码:[ http://code.google.com/p/swfobject/wiki/SWFObject_2_0_generator ]。