as3+xml+asp+access做的有獎問答

來源:互聯網
上載者:User

XML部份 複製代碼 代碼如下:<?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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.