您的位置:首页 > 其它

.net中如何生成Flash式的图片切换效果

2009-06-17 12:24 369 查看
在做新闻发布系统的时候,目前有一种很流行的做法就是将多幅图片新闻的图片合成一个flash,flash右下角有12345等标记,可以在多幅图片中进行切换。
这种方式在.net中的实现方式如下:
第一步:首先在.Net后台生成javascript语句function indexpic()。
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="";
        DataSet ds=commonfunction .GetPicNews ();
        int count=ds.Tables [0].Rows.Count;
        for(int i=0;i<count ;i++)
        {
            if(i!=0)pics+="|"+ds.Tables [0].Rows [i]["index_pic"].ToString ();
            else pics+=ds.Tables [0].Rows [i]["index_pic"].ToString ();
            if(i!=0) links +="|"+"SingleInfo.aspx?id="+ds.Tables [0].Rows [i]["id"].ToString ();
            else links +="SingleInfo.aspx?id="+ds.Tables [0].Rows [i]["id"].ToString ();
            if(i!=0)texts +="|"+ds.Tables [0].Rows [i]["title"].ToString ();
            else texts +=ds.Tables [0].Rows [i]["title"].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=/"http://travel.zjg.js.cn/config/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 ());
    }
 
第二步:在页面的pageload函数中注册此Javascript函数,方法如下:
protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
            RegisterStartupScript();
    }
 
第三步:在需要放置flash的地方(aspx页面中的某个位置),引用上面注册过的javascript函数
<script  type ="text/javascript" >indexpic();</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: