在HTML代码中嵌入Flash文件的解决方案!(下)
关于我的SWFObject V1.5的使用过程,以上篇中的介绍暂时告一段落了,下面我将会带领SWFObject V2.1出场与大家见面,如果我早一点结识V2.1的话,或许就不会受到“等待HTML DOM加载”问题的侵扰了。
首先,给大家简要介绍一下V2.1语法的调用示例:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
//1、使用Json初始化变量、参数、属性
var flashvars = {
name1: "hello",
name2: "world",
name3: "foobar"
};
var params = {
menu: "false"
};
var attributes = {
id: "dynamicContent2",
name: "dynamicContent2"
};
swfobject.embedSWF("test6_flashvars.swf", "content2", "300", "120", "6.0.0", "expressInstall.swf", flashvars, params, attributes);
//2、传统的初始化设置,效果一样
var flashvars = {};
flashvars.name1 = "hello";
flashvars.name2 = "world";
flashvars.name3 = "foobar";
var params = {};
params.menu = "false";
var attributes = {};
attributes.id = "dynamicContent3";
attributes.name = "dynamicContent3";
swfobject.embedSWF("test6_flashvars.swf", "content3", "300", "120", "6.0.0",
"expressInstall.swf", flashvars, params, attributes);
//3、直接写在后面,就一句话,简洁剽悍,不拖泥带水
swfobject.embedSWF("test6_flashvars.swf", "content5", "300", "120",
"6.0.0", "expressInstall.swf", {name1:"hello",name2:"world",name3:"foobar"}, {menu:"false"}, {id:"dynamicContent5",name:"dynamicContent5"});
</script>
从我个人来讲,我比较喜欢上面的第三种写法,下面即将提到,我在HTML代码中嵌入Flash文件的最终解决方案中,就是采取的第三种风格调用的swfobject.embedSWF()。而且您是否发现了,在这三种写法中
上篇中采取的解决方案看来,似乎已经能够满足大部分需求,而且兼容性似乎也还过得去,理应能够满足绝多数朋友的需求,也未尝不可是一个过得去的解决方案。但是,有一种比较极端的情况被我发现,就是在:
new SWFObject("http://www.pec365.com/Flash/20071113.swf", "mymovie", "304", "367", "7", "#FFFFFF");
的时候,如果传入的Flash文件的地址有误,又或者该Flash文件在服务器中被删除掉了,那么你将看到一种最不愿意看到的情况,示例如下:
<html>
<title>DEMO</title>
<head>
<script type="text/javascript" src="swfobject_source.js"></script>
</head>
<body>
<form id="Form1">
<div id="flashcontent">
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" border="0" />
</a>
</div>
</form>
<script type="text/javascript">
// 注意,我在Flash文件名前加了一个f
var so = new SWFObject("http://www.pec365.com/Flash/f20071113.swf", "mymovie", "304", "367", "7", "#FFFFFF");
so.write("flashcontent");
</script>
</body>
</html>