(21)顯示數(shù)據(jù)制作完成,再編寫留言發(fā)送和程序,提交留言數(shù)據(jù)的ASP程序“post.asp”。
ASP/Visual Basic代碼
<%@LANGUAGE="VBSCRIPT"%> <!--#include file="head/conn.asp" --> <% postName=trim(request.form("in_name")) qq=trim(request.form("in_qq")) title=trim(request.form("in_title")) msg=trim(request.form("in_content")) set add = Server.CreateObject("ADODB.Recordset") add.ActiveConnection = conn add.Source = "SELECT * FROM book" add.CursorType = 0 add.CursorLocation = 2 add.LockType = 2 add.Open() add_numRows = 0 add.addnew if qq<>"" then add("qq")=int(qq) else add("qq")=0 end if add("name")=postName add("title")=title add("msg")=msg add.update add.Close() set add=nothing %> |
技術(shù)看板:ASP代碼解釋
第4~7行,接收Flash上傳來的值。
第17~21行,因?yàn)?ldquo;qq”字段是整型的,所以要先判斷用戶留言時(shí)是否有填寫QQ號(hào),默認(rèn)為0。
第22~25行,寫入數(shù)據(jù)庫(kù)。
(22)在Flash中制作留言框“WriteBox”,如圖14- 10 所示。
圖14-10 留言發(fā)送框
(23)發(fā)送成功以后,會(huì)有一個(gè)提示框,制作提示框命名為“sendDia”如圖14- 11 所示。
圖14-11 提示框
(24)編寫“WriteBox.as”代碼。
AS3代碼
package com.GB4{ import flash.display.*; import flash.net.URLRequest; import flash.net.URLLoader; import flash.net.URLVariables; import flash.net.URLRequestMethod; import flash.text.TextField; import flash.events.MouseEvent; import flash.events.*; public class WriteBox extends MovieClip { public function WriteBox() { stop(); inputBox.sendBt.addEventListener(MouseEvent.CLICK, sendData); sendDia.visible=true; } private function sendData(event:MouseEvent):void { if (inputBox.showName.text==""||inputBox.msg.text=="") { return; } var myLoader:URLLoader = new URLLoader(); var loadUrl:URLRequest=new URLRequest("http://localhost/GB4/post.asp"); var variables:URLVariables = new URLVariables(); &nbs, p; , ; variable, , s.in_name=inputBox.showName.text; variables.in_qq=inputBox.qq.text; variables.in_title=inputBox.title.text; variables.in_content = inputBox.msg.text ; loadUrl.data=variables; loadUrl.method=URLRequestMethod.POST; myLoader.addEventListener(Event.COMPLETE,loadComplete); myLoader.addEventListener(IOErrorEvent.IO_ERROR,loadError); myLoader.load(loadUrl); } private function loadComplete(event:Event):void { sendDia.visible=true; inputBox.visible=false; inputBox.showName.text=inputBox.qq.text=inputBox.title.text=inputBox.msg.text=""; //留言成功以后,清空所有輸入框 } private function loadError(event:IOErrorEvent):void { trace("加載出錯(cuò)"); } } } |
技術(shù)看板:ASP代碼解釋
第14行,先隱藏提示框。
第17行,如果用戶沒有輸入文字則不發(fā)送。
第20~23行,發(fā)送Flash上傳來的值。
第32行,發(fā)送成功,。
第22~25行,寫入數(shù)據(jù)庫(kù)。
(25)制作完成測(cè)試程序。
進(jìn)入論壇參與討論交流:http://www.missyuan.com/viewthread.php?tid=425889