1、创建一个用户控件 SwfPlayer.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SwfPlayer.ascx.cs" Inherits="SwfPlayer" %>
后台代码:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
public partial class SwfPlayer : System.Web.UI.UserControl
{
??? private string _File;
??? private int _Width;
??? private int _Height;
??? //设置Flash宽度属性
??? public int Width
??? {
??????? set { _Width = value; }
??? }
??? //设置Flash高度属性
??? public int Height
??? {
??????? set { _Height = value; }
??? }
??? //Flash文件
??? public string File
??? {
??????? set { _File = value; }
??? }
??? protected void Page_Load(object sender,EventArgs e)
??? {
??? }
??? //重新Render方法
??? protected override void Render(HtmlTextWriter writer)
??? {
??????? //Flash对象
??????? StringBuilder sb = new StringBuilder();
??????? sb.AppendFormat("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,19,0'width='{0}' height='{1}'>",_Width,_Height);
??????? sb.AppendFormat("<param name='movie' value='{0}'>",_File);
??????? sb.AppendFormat("<param name='quality' value='high'>");
??????? sb.AppendFormat("<embed src='{0}' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='{1}' height='{2}'></embed>",_File,_Height);
??????? sb.Append("</object>");
??????? writer.Write(sb.ToString());
??? }
}
?
2、引用页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SwfPlayPage.aspx.cs" Inherits="SwfPlayPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Src="SwfPlayer.ascx" TagName="SwfPlayer" TagPrefix="uc1" %>
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> ??? <title></title> </head> <body> ??? <form id="form1" runat="server"> ??? <div> ??????? <uc1:SwfPlayer ID="SwfPlayer1" runat="server" File="Files/photo.swf" Width="400" Height="300"?/> ??? </div> ??? </form> </body> </html>