index.aspx前台:
<div id="ShowAD">
<script type="text/javascript" language="javascript">
var pic_width=698 //图片宽度
var pic_height=184 //图片高度
var swfpath = 'picviewer.swf' //swf文件路径地址,需要'picviewer.swf文件置于index.aspx文件同一级别目录下
var swf_height = 184
var pics='<%=BindADOne() %>';// 得到 var pics='ImageAD/01.jpg|ImageAD/02.jpg|ImageAD/03.jpg|ImageAD/04.jpg';
var links='<%=BindADTwo() %>'; // 得到 var links='Item.aspx?Id=2|Item.aspx?Id=2|Item.aspx?Id=2|Item.aspx?Id=2';
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ pic_width +'" height="'+ swf_height +'">');
document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="'+swfpath+'"><param name="quality" value="high"><param name="bgcolor" value="#ffffff">');
document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
document.write('<param name="FlashVars" value="pics='+ pics +'&links='+ links +'&borderwidth='+pic_width+'&borderheight='+pic_height+'">');
document.write('<embed src="'+swfpath+'" wmode="opaque" FlashVars="pics='+ pics +'&links='+ links +'&borderwidth='+pic_width+'&borderheight='+pic_height+'" menu="false" bgcolor="#ffffff" quality="high" width="'+ pic_width +'" height="'+ pic_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
</script>
</div>
index.aspx后台:
public string BindADOne() {
string txtPath = Server.MapPath("App_Data/ad.xml");
string reImage=string.Empty;
XmlDocument doc = new XmlDocument();
doc.Load(txtPath);
XmlNodeList listImage = doc.GetElementsByTagName("Image");
foreach (XmlNode node in listImage) {
reImage += node.InnerText.ToString() + "|";
}
txtImage = reImage.Substring(0,reImage.LastIndexOf("|"));
return txtImage;
}
public string BindADTwo()
{
string txtPath = Server.MapPath("App_Data/ad.xml");
string reLink = string.Empty;
XmlDocument doc = new XmlDocument();
doc.Load(txtPath);
XmlNodeList listLink = doc.GetElementsByTagName("ImageLink");
foreach (XmlNode nodeLink in listLink)
{
reLink += nodeLink.InnerText + "|";
}
txtLink = reLink.Substring(0,reLink.LastIndexOf("|"));
return txtLink;
}
App_Data/ad.xml:
<?xml version="1.0" encoding="gb2312"?>
<IndexAd>
<ad>
<Id>1</Id>
<Name>图片1</Name>
<Image>ImageAD/01.jpg</Image>
<ImageLink>Item.aspx?Id=2</ImageLink>
</ad>
<ad>
<Id>2</Id>
<Name>图片2</Name>
<Image>ImageAD/02.jpg</Image>
<ImageLink>Item.aspx?Id=2</ImageLink>
</ad>
<ad>
<Id>3</Id>
<Name>图片3</Name>
<Image>ImageAD/03.jpg</Image>
<ImageLink>Item.aspx?Id=2</ImageLink>
</ad>
<ad>
<Id>4</Id>
<Name>图片4</Name>
<Image>ImageAD/04.jpg</Image>
<ImageLink>Item.aspx?Id=2</ImageLink>
</ad>
</IndexAd>
picviewer.swf: