用ASP真正动态实现FLASH幻灯片新闻代码
作者:随然 日期:2008-11-11
在网上看了一些用ASP实现FLASH幻灯片新闻的代码,觉得都太繁琐了,没有真正实现动态的功能,我按照Javascript的思路,写了一个ASP代码,希望能对大家有所帮助。
对于代码里面需要使用的flash文件,只需要focus.swf就可以了,网上到处都有下。下载后使用我提供的代码就可以。
复制内容到剪贴板 程序代码
<table>
<tr>
<TD width=390>
<%
set conn=server.createobject("adodb.connection")
DBPath = Server.MapPath(data/news.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
Set rs= Server.CreateObject("ADODB.Recordset")
newsnum=5 '设置你要调用的新闻条数
sql="select top "&newsnum&" * from news where imgtype=1 order by articleid desc"
rs.open sql,conn,1,1
dim imgnum
imgnum=1
do while not (rs.eof or err)
articleid=rs("articleid")
titleImg=rs("titleImg")
classid=rs("classid")
if len(rs("title"))>15 then
title=left(rs("title"),14)&"..."
else
title=rs("title")
end if
if imgnum=1 then
imgUrl="news/"&titleImg
imgtext=title
imgLink="http://scdyzx.cn/news/show.aspx?id="&rs("articleid")&"&cid="&classid
imgLink=vbsEscape(imgLink)
else
imgUrl=imgUrl&"|news/"&titleImg
imgtext=imgtext&"|"&title
imgLinkadd="http://scdyzx.cn/news/show.aspx?id="&rs("articleid")&"&cid="&classid
imgLink=imgLink&"|"&vbsEscape(imgLinkadd)
end if
imgnum=imgnum+1
rs.movenext
loop
rs.close
Function vbsEscape(str) '类似于Javascript的escape方法对文字和链接加密
dim i,s,c,a
s=""
For i=1 to Len(str)
c=Mid(str,i,1)
a=ASCW(c)
If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
s = s & c
ElseIf InStr("@*_+-./",c)>0 Then
s = s & c
ElseIf a>0 and a<16 Then
s = s & "%0" & Hex(a)
ElseIf a>=16 and a<256 Then
s = s & "%" & Hex(a)
Else
s = s & "%u" & Hex(a)
End If
Next
vbsEscape = s
End Function
%>
<script type="text/javascript">
var focus_width=380
var focus_height=170
var text_height=20
var swf_height = focus_height+text_height
var pics="<%=imgUrl%>"
var link="<%=imgLink%>"
var texts="<%=imgtext%>"
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 +'">');
document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="image_index/focus.swf"><param name="quality" value="high"><param name="bgcolor" value="#FFFFFF">');
document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
document.write('<param name="FlashVars" value="pics='+pics+'&links='+link+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
document.write('<embed src="image_index/pixviewer.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+link+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#FFFFFF" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); document.write('</object>');
</script>
</td>
</tr>
</table>
<tr>
<TD width=390>
<%
set conn=server.createobject("adodb.connection")
DBPath = Server.MapPath(data/news.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
Set rs= Server.CreateObject("ADODB.Recordset")
newsnum=5 '设置你要调用的新闻条数
sql="select top "&newsnum&" * from news where imgtype=1 order by articleid desc"
rs.open sql,conn,1,1
dim imgnum
imgnum=1
do while not (rs.eof or err)
articleid=rs("articleid")
titleImg=rs("titleImg")
classid=rs("classid")
if len(rs("title"))>15 then
title=left(rs("title"),14)&"..."
else
title=rs("title")
end if
if imgnum=1 then
imgUrl="news/"&titleImg
imgtext=title
imgLink="http://scdyzx.cn/news/show.aspx?id="&rs("articleid")&"&cid="&classid
imgLink=vbsEscape(imgLink)
else
imgUrl=imgUrl&"|news/"&titleImg
imgtext=imgtext&"|"&title
imgLinkadd="http://scdyzx.cn/news/show.aspx?id="&rs("articleid")&"&cid="&classid
imgLink=imgLink&"|"&vbsEscape(imgLinkadd)
end if
imgnum=imgnum+1
rs.movenext
loop
rs.close
Function vbsEscape(str) '类似于Javascript的escape方法对文字和链接加密
dim i,s,c,a
s=""
For i=1 to Len(str)
c=Mid(str,i,1)
a=ASCW(c)
If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
s = s & c
ElseIf InStr("@*_+-./",c)>0 Then
s = s & c
ElseIf a>0 and a<16 Then
s = s & "%0" & Hex(a)
ElseIf a>=16 and a<256 Then
s = s & "%" & Hex(a)
Else
s = s & "%u" & Hex(a)
End If
Next
vbsEscape = s
End Function
%>
<script type="text/javascript">
var focus_width=380
var focus_height=170
var text_height=20
var swf_height = focus_height+text_height
var pics="<%=imgUrl%>"
var link="<%=imgLink%>"
var texts="<%=imgtext%>"
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 +'">');
document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="image_index/focus.swf"><param name="quality" value="high"><param name="bgcolor" value="#FFFFFF">');
document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
document.write('<param name="FlashVars" value="pics='+pics+'&links='+link+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
document.write('<embed src="image_index/pixviewer.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+link+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#FFFFFF" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); document.write('</object>');
</script>
</td>
</tr>
</table>
[本日志由 随然 于 2008-12-14 00:00 AM 编辑]
上一篇: asp函数实现javascript里的escape函数和unescape函数功能下一篇: 胃镜检查真的很恶心
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: ASP 网页
相关日志:
评论: 4 | 引用: 0 | 查看次数: 13603
123[2008-12-13 02:23 PM | | | 220.173.41.137 | | 取消审核 | 回复]
沙发你好啊,怎么没有pixviewer.swf的下载的?发到我邮箱abj23@163.com谢谢!
随然"/> 随然 回复 [2008-12-13 11:51 PM]
你好,只需要focus.swf就可以了,网上到处都有下。你使用我提供的代码就可以。
发表评论