在项目里面,我们就要用到这个控件了,解决了我们的问题,但是不是很难
不在这里多说,先看下面的代码吧:
using
System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;
namespace FlashAdRotator
{
/**//**//**//// <summary>
/// fpAdRotator 的摘要说明。
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:fpAdRotator runat=server></{0}:fpAdRotator>")]
public class fpAdRotator : System.Web.UI.WebControls.AdRotator
{
private bool isflashad;
private string imgurl;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
/**//**//**//// <summary>
/// 将此控件呈现给指定的输出参数。
/// </summary>
/// <param name="output"> 要写出到的 HTML 编写器 </param>
protected override void Render(HtmlTextWriter output)
{
try
{
if(isflashad==true)
{
StringBuilder sb=new StringBuilder("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"");
sb.Append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width={0} height={1}>");
sb.Append("<param name=\"movie\" value={2} />");
sb.Append("<param name=\"quality\" value=\"high\"/>");
sb.Append("<embed src={3} quality=\"high\"");
sb.Append("pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width={4} height={5}></embed></object>");
StringBuilder outstr=new StringBuilder();
outstr.AppendFormat(sb.ToString(),this.Width,this.Height,this.imgurl,this.imgurl,this.Width,this.Height);
output.Write(outstr);
}
if(isflashad==false)
{
//this.Render(output);
base.Render (output);
}
}
catch
{
StringBuilder sb=new StringBuilder("<table><tr>广告媒体不存在<td></td></tr><table>");
output.Write(sb);
}
}
protected override void OnAdCreated(AdCreatedEventArgs e)
{
if(e.ImageUrl.ToLower().IndexOf(".swf")!=-1)
{
this.isflashad=true;
this.imgurl=e.ImageUrl;
}
else
{
this.isflashad=false;
}
}
}
}
以上就是主要的代码,
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;
namespace FlashAdRotator
{
/**//**//**//// <summary>
/// fpAdRotator 的摘要说明。
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:fpAdRotator runat=server></{0}:fpAdRotator>")]
public class fpAdRotator : System.Web.UI.WebControls.AdRotator
{
private bool isflashad;
private string imgurl;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
/**//**//**//// <summary>
/// 将此控件呈现给指定的输出参数。
/// </summary>
/// <param name="output"> 要写出到的 HTML 编写器 </param>
protected override void Render(HtmlTextWriter output)
{
try
{
if(isflashad==true)
{
StringBuilder sb=new StringBuilder("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"");
sb.Append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width={0} height={1}>");
sb.Append("<param name=\"movie\" value={2} />");
sb.Append("<param name=\"quality\" value=\"high\"/>");
sb.Append("<embed src={3} quality=\"high\"");
sb.Append("pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width={4} height={5}></embed></object>");
StringBuilder outstr=new StringBuilder();
outstr.AppendFormat(sb.ToString(),this.Width,this.Height,this.imgurl,this.imgurl,this.Width,this.Height);
output.Write(outstr);
}
if(isflashad==false)
{
//this.Render(output);
base.Render (output);
}
}
catch
{
StringBuilder sb=new StringBuilder("<table><tr>广告媒体不存在<td></td></tr><table>");
output.Write(sb);
}
}
protected override void OnAdCreated(AdCreatedEventArgs e)
{
if(e.ImageUrl.ToLower().IndexOf(".swf")!=-1)
{
this.isflashad=true;
this.imgurl=e.ImageUrl;
}
else
{
this.isflashad=false;
}
}
}
}
但是我也有很我的地方不是很明白,
如果其中的
sb.Append(
"
codebase=\
"
http:
//
download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width={0} height={1}>");
sb.Append( " pluginspage=\ " http: // www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width={4} height={5}></embed></object>");
URL地址变了,那么就不能正常的显示出来Flash文件了
sb.Append( " pluginspage=\ " http: // www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width={4} height={5}></embed></object>");
至于其中的URL地址变不变,我都得考虑的这个问题,
请高手指点