as3+xml+asp+access做的有奖问答
<?xml version="1.0" encoding="utf-8"?>
<li>
<id>
<pp>1、中国114黄页贵港站的网址是?</pp>
<aa>www.gg114chn.com</aa>
<aa>gg.114chn.com</aa>
<aa>www.114chn.com</aa>
<aa>www.114.com</aa>
</id>
<id>
<pp>2、中国114黄页的联系电话号码是多少?</pp>
<aa>0775—4320568</aa>
<aa>0775—4553709</aa>
<aa>0775—4563709</aa>
<aa>114</aa>
</id>
<id>
<pp>3、中国114黄页贵港运营中心客服QQ是?</pp>
<aa>10000</aa>
<aa>380463801</aa>
<aa>1015651717</aa>
<aa>854512401</aa>
</id>
<id>
<pp>4、中国114黄页的总公司是?</pp>
<aa>中国移动</aa>
<aa>中国电信</aa>
<aa>中国114号码百事通</aa>
<aa>北京互联星空文化传播有限公司</aa>
</id>
</li>
AS3类-myform,放在一个myfirst包里。生成一个主要由ComboBox组件组的表单,
代码如下:
package myfirst{
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
import flash.text.TextField;
import flash.text.TextFieldType;
import fl.data.DataProvider;
import fl.controls.Button;
import fl.controls.ComboBox;
import fl.controls.SelectableList;
import flash.system.System;
public class myform extends Sprite {
System.useCodePage = true;
var a_form:String="";
var a_num:int;
var a_array:Array=new Array();
public function myform():void {
var loader:URLLoader=new URLLoader;
configureListeners(loader);
var request:URLRequest=new URLRequest("pa.xml");
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE,completeHandler);
}
private function completeHandler(event:Event):void {
XML.ignoreProcessingInstructions=true;
var loader:URLLoader=URLLoader(event.target);
var myxml:XML=XML(loader.data.toString());
a_num=myxml.id.pp.length();
for (var i:int=0; i <= a_num - 1; i++) {
var p_text:TextField=new TextField();
p_text.text=myxml.id[i].pp;
p_text.width=250;
p_text.y=i*50;
addChild(p_text);
var mycombobox:ComboBox=new ComboBox();
mycombobox.dropdownWidth =180;
mycombobox.move(20,20+i*50);
mycombobox.prompt="选择答案";
mycombobox.addEventListener(Event.CHANGE, cardSelected);
addChild(mycombobox);
for (var j:int=0; j<=3; j++) {
mycombobox.addItem({label:myxml.id[i].aa[j]});
}
}
}
private function cardSelected(event:Event):void {
var cb:ComboBox=event.currentTarget as ComboBox;
var cbindex:int=getChildIndex(cb)/2;
var aa:int=cb.selectedIndex;
a_array[cbindex]=(String(aa));
}
public function mm(event:Event):void {
for (var k:int=0; k<=a_num-1; k++) {
a_form+=String(a_array[k]);
}
trace(a_form);
}
}
}
同样放在myfirst包里的另一个类url_asp,主要用于连接ASP文件
代码如下:
package myfirst{
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
import flash.text.TextField;
import flash.text.TextFieldType;
import fl.controls.Button;
import fl.controls.TextInput;
import flash.system.System;
public class url_asp extends Sprite {
public function url_asp() {
System.useCodePage=true;
var form_name:TextField=new TextField();
var form_tel:TextField=new TextField();
form_name.text="姓名:";
form_tel.text="电话:";
form_name.x=100;
form_name.y=350;
form_tel.x=100;
form_tel.y=300;
addChild(form_name);
addChild(form_tel);
var form_value=new myform();
form_value.x=10;
form_value.y=10;
addChild(form_value);
var myname:String="";
var telephone:String="";
var a_form:String ="";
var variables:URLVariables=new URLVariables();
var myrequest:URLRequest=new URLRequest("save.asp");
var loader:URLLoader = new URLLoader();
var mybutton1:Button=new Button();
mybutton1.x=180;
mybutton1.y=250;
mybutton1.label="确认答案";
mybutton1.addEventListener(MouseEvent.CLICK,form_value.mm);
addChild(mybutton1);
var myname_input:TextInput=new TextInput();
myname_input.x=180;
myname_input.y=350;
addChild(myname_input);
var telephone_input:TextInput=new TextInput();
telephone_input.x=180;
telephone_input.y=300;
addChild(telephone_input);
var mybutton:Button=new Button();
mybutton.x=180;
mybutton.y=400;
mybutton.label="提交信息";
addChild(mybutton);
mybutton.addEventListener(MouseEvent.CLICK,onclik);
function onclik(event:Event):void {
variables.myname=myname_input.text;
variables.telephone=telephone_input.text;
variables.a_form= form_value.a_form;
trace( form_value.a_form);
myrequest.data=variables;
myrequest.method=URLRequestMethod.POST;//指定 URLRequest 对象为 POST。
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.load(myrequest);//发送数据
}
}
}
}
建一个FLA,言文档类就写myfirst.url_asp。
ASP部份,三个文件。
---conn.asp---
asp文件1数据库连接
代码如下:
<%
Dim conn
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("msg.mdb")
%>
--save.asp----
asp文件2保存数据
代码如下:
<!-- #include file=conn.asp -->
<%
if request("myname")="" then
response.Write("no data")
response.End()
else
myname=Request("myname")
telephone=Request("telephone")
a_form=Request("a_form")
sql="Insert into data (myname,telephone,a_form) values ('"&myname&"','"&telephone&"','"&a_form&"')"
conn.Execute(sql)
conn.close
Set conn=Nothing
Response.Write "ok"
end if
%>
----list.asp------
asp文件3查看答题者
代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
body {
background-color: #B57202;
}
-->
</style></head>
<!-- #include file="conn.asp" -->
<body>
<%
dim rs_zl
set rs_zl =server.createobject("adodb.recordset")
rs_zl.open "select * from data",conn,1,1
rs_zl.pagesize=15
if request("page")<>"" then
epage=cint(request("page"))
if epage<1 then epage=1
if epage>rs_zl.pagecount then epage=rs_zl.pagecount
else
epage=1
end if
rs_zl.absolutepage=epage
%>
<table width="750" border="0" cellpadding="2" cellspacing="2">
<tr bgcolor="#666666">
<td>ID</td>
<td>姓名</td>
<td>电话</td>
<td>答案</td>
<td> </td>
</tr>
<%
for i=0 to rs_zl.pagesize-1
if rs_zl.eof then exit for
%>
<tr bgcolor="#666666">
<td><%=rs_zl("id")%></td>
<td><%=rs_zl("myname")%></td>
<td><%=rs_zl("telephone")%></td>
<td><%=rs_zl("a_form")%></td>
<td> </td>
</tr>
<%
rs_zl.movenext
next
%>
</table>
<table width="530">
<tr>
<td width="124" height="38"> </td>
<td width="259">
<p align="center">
<a href="list.asp">首页</a>
<a href="list.asp?page=<%=epage-1%>">前一页</a>
<a href="list.asp?page=<%=epage+1%>">后一页</a>
<a href="list.asp?page=<%=rs_zl.pagecount%>">末页</a>
</p>
<p align="center">现在是第<%=epage%>页一共有<%=rs_zl.pagecount%>页</p>
</td>
<td width="131"> </td>
</tr>
</table>
<%
rs_zl.close
set rs_zl = nothing
conn.close()
%>
</body>
</html>