引用:http://www.cnblogs.com/xugang/archive/2011/03/19/1988796.html
首先,创建一个独立的JavaScript 文件(如:flash.js)用于添加Flash 播放器。代码如下:
function CreateFlash(idad,swfurl,wad,had,vs){
var str="<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\""+wad+"\" height=\""+had+"\" id=\""+idad+"\" align=\"middle\">";str+="<param name=\"allowScriptAccess\" value=\"always\">";str+="<param name=\"quality\" value=\"high\">";str+="<param name=\"wmode\" value=\"opaque\">";str+="<param name=\"movie\" value=\""+swfurl+"\">";str+="<param name=\"flashvars\" value=\""+vs+"\">";str+="<embed src=\""+swfurl+"\" flashvars=\""+vs+"\" quality=\"high\" wmode = \"opaque\" width=\""+wad+"\" height=\""+had+"\" name=\""+idad+"\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">";str+="</object>";document.write(str);}
var str="<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\""+wad+"\" height=\""+had+"\" id=\""+idad+"\" align=\"middle\">";str+="<param name=\"allowScriptAccess\" value=\"always\">";str+="<param name=\"quality\" value=\"high\">";str+="<param name=\"wmode\" value=\"opaque\">";str+="<param name=\"movie\" value=\""+swfurl+"\">";str+="<param name=\"flashvars\" value=\""+vs+"\">";str+="<embed src=\""+swfurl+"\" flashvars=\""+vs+"\" quality=\"high\" wmode = \"opaque\" width=\""+wad+"\" height=\""+had+"\" name=\""+idad+"\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">";str+="</object>";document.write(str);}
然后,创建一个XML 文件(如:inddata.xml)用于保存图片的路径地址。代码如下:
<data>
<l big="big_img/big_img1.jpg" small="small_img/small_img1.jpg" url="http://xugang.cnblogs.com"/>
<l big="big_img/big_img2.jpg" small="small_img/small_img2.jpg" url="http://xugang.cnblogs.com"/>
<l big="big_img/big_img3.jpg" small="small_img/small_img3.jpg" url="http://xugang.cnblogs.com"/>
</data>
<l big="big_img/big_img1.jpg" small="small_img/small_img1.jpg" url="http://xugang.cnblogs.com"/>
<l big="big_img/big_img2.jpg" small="small_img/small_img2.jpg" url="http://xugang.cnblogs.com"/>
<l big="big_img/big_img3.jpg" small="small_img/small_img3.jpg" url="http://xugang.cnblogs.com"/>
</data>
注意:在此XML 文件中指定大图片和小图标的地址路径。
最后,在网页HTML 文件中,编写代码如下:
<!-- head 标签中,添加JS引用 -->
<script src="../js/flash.js" language="javascript"></script>
......
<!-- body 标签中,添加显示flash的代码 -->
<div class="bnrInd">
<script language="javascript">
//初始化Flash时,包含xml路径
CreateFlash("banner", "../AboutUs/banner.swf", 1002, 280, "data=inddata.xml");
</script>
</div>
<script src="../js/flash.js" language="javascript"></script>
......
<!-- body 标签中,添加显示flash的代码 -->
<div class="bnrInd">
<script language="javascript">
//初始化Flash时,包含xml路径
CreateFlash("banner", "../AboutUs/banner.swf", 1002, 280, "data=inddata.xml");
</script>
</div>
效果如下:
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]