播放Flash的用户控件

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,0,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, _Width, _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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

感谢一路走过的人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值