构建一个滚动图片新闻
所需的flash组件已找到,现需在后台构造flash组件所需的字段:pics+links+texts(为flash展示的图片,图片的超链接和下方显示的文字)
我后台代码如下:
StringBuffer pics = new StringBuffer("'");
StringBuffer texts = new StringBuffer("'");
StringBuffer links = new StringBuffer("'");
for(int i=0;i<picList.size();i++){
Article o=picList.get(i);
pics.append(java.net.URLEncoder.encode("/images/articles/prototype/140x/"+o.getUrl(),"utf-8"));
texts.append(java.net.URLEncoder.encode(o.getName(),"utf-8"));
links.append(java.net.URLEncoder.encode("/article/list/manage.do?method=showItem&id="+o.getId(),"utf-8"));
if(i!=(picList.size()-1)){
pics.append("|");
texts.append("|");
links.append("|");
}

}
pics.append("'");
texts.append("'");
links.append("'");
……
request.setAttribute("pics",pics.toString());
request.setAttribute("links",links.toString());
request.setAttribute("texts",texts.toString());而前台flash的代码如下:
<script type="text/javascript">
<!--
var focus_width=375;
var focus_height=210;
var text_height=20;
var swf_height = focus_height+text_height;
var pics=<%=(String)request.getAttribute("pics")%>;
var links=<%=(String)request.getAttribute("links")%>;
var texts=<%=(String)request.getAttribute("texts")%>;
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="/flash/Flash.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='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">')
document.write('<embed src="/flash/Flash.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#cccccc" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
//-->
</script>现在就是不能正常工作,这到底是怎么回事呢