图片切换flash

 

解决方案图:

数据库图:

效果图:

 

在前台写入:

<form id="form1" runat="server">

    <div>

   

        <table>

            <tr>

                <td bgcolor="#333333" height="173" width="250" align ="center" ><script  type ="text/javascript" >indexpic();</script>

</td>

            </tr>

        </table>

   

    </div>

 

    </form>

 

在后台写入

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Data;

using System.Text;

 

namespace WebApp_Validate

{

    public partial class WebForm1 : System.Web.UI.Page

    {

        SqlConnection conn = new SqlConnection("Data Source=WWW-34592C15BC2\\SQLSERVER2005;Initial Catalog=test;Integrated Security=True");

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                RegisterStartupScript();

            }

        }

        public DataSet getPicture()

        {

            SqlCommand cmd = new SqlCommand("Select * from T_Image", conn);

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            DataSet ds = new DataSet();

            da.Fill(ds);

            return ds;

        }

        private void RegisterStartupScript()

        {

            string strKey = "picflash";

 

            StringBuilder str = new StringBuilder();

            str.Append("<script type=text/javascript>function indexpic(){var focus_width=287;var focus_height=173;var text_height=20;");

 

            str.Append("var swf_height = focus_height+text_height;");

 

            string pics = "";//路径

            string links = "";//连接

            string texts = "";//标题

 

            //从数据库中动态获取数据,将数据写入ds

            DataSet ds = this.getPicture();

 

 

            int count = ds.Tables[0].Rows.Count;

            for (int i = 0; i < count; i++)

            {

 

                //将数据库中的数据写入flash的参数

                if (i != 0) pics += "|" + ds.Tables[0].Rows[i]["imgurl"].ToString();

                else pics += ds.Tables[0].Rows[i]["imgurl"].ToString();

                if (i != 0) links += "|" + "" + ds.Tables[0].Rows[i]["imglink"].ToString();

                else links += "" + ds.Tables[0].Rows[i]["imglink"].ToString();

                if (i != 0) texts += "|" + ds.Tables[0].Rows[i]["imgtitle"].ToString();

                else texts += ds.Tables[0].Rows[i]["imgtitle"].ToString();

 

            }

            str.Append("var pics='" + pics + "';");

            str.Append(" var links='" + links + "';");

            str.Append(" var texts='" + texts + "';");

 

            str.Append("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=\"'+ focus_width +'\" height=\"'+ swf_height +'\">');");

            str.Append("document.write('<param name=\"allowScriptAccess\" value=\"sameDomain\"><param name=\"movie\" value=\"../pixviewer.swf\"><param name=\"quality\" value=\"high\"><param name=\"bgcolor\" value=\"#999898\">');");

            str.Append("document.write('<param name=\"menu\" value=\"false\"><param name=wmode value=\"opaque\">');");

            str.Append("document.write('<param name=\"FlashVars\" value=\"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'\">');");

            str.Append("document.write('</object>');}</script>");

 

            Page.RegisterClientScriptBlock(strKey, str.ToString());//注册indexpic函数

 

 

        }

    }

}

 

注意:pixviewer.swf得下载:pixviewer 

转:"心得感觉"博客园

原文地址:https://www.cnblogs.com/KimhillZhang/p/1750207.html