Flash ActionScript 3.0 通过asp.net 访问 数据库
在服务器建立test.aspx内容:
<%@ Page language="c#" CodeFile="test.aspx.cs" AutoEventWireup="false" Inherits="test" %>
test.aspx.cs 内容:
public partial class test : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处定义dataset 并且访问数据库。
DataSet ds = new DataSet();
ds = //访问数据库的function();
// 在此处把dataset转换成xml发送回去。
Response.Write( ds.GetXml());
}
}
Flash 端:
新建ActionScript 3.0 的Flash。
windows--->components-->DataGird 托拽到界面中。 命名为:aDg
在第一帧action中
写下以下代码
import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;
import flash.net.*;
import flash.display.*;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.sendToURL;
import flash.external.ExternalInterface;
import flash.xml.XMLDocument;
import flash.xml.XMLNode;
import flash.xml.XMLNodeType;
var loader:URLLoader = new URLLoader();
var URLpreFix:String="http://itd-cecilia/website/test.aspx"; //http://itd-cecilia/website/test.aspx为服务器地址
getresult1();
function getresult1(){
var url:String=URLpreFix;
var request:URLRequest=new URLRequest(url);
trace("sendToURL);
var loader:URLLoader = new URLLoader();
loader.dataFormat=URLLoaderDataFormat.TEXT;
configureListeners(loader);
loader.load(request);
stop();
}
function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
function completeHandler(event:Event):void {
var loader:URLLoader=URLLoader(event.target);
trace("completeHandler: " + loader.data);
var teamXML:XML = new XML(loader.data);
var RoomIDCol:DataGridColumn=new DataGridColumn("RoomID");
RoomIDCol.headerText="ID";
RoomIDCol.width=20;
var RoomNameCol:DataGridColumn=new DataGridColumn("RoomName");
RoomNameCol.headerText="Name";
RoomNameCol.width=30;
var RoomDecCol:DataGridColumn=new DataGridColumn("RoomDescription");
RoomDecCol.headerText="Dec";
RoomDecCol.width=30;
var RoomLocatCol:DataGridColumn=new DataGridColumn("RoomLocation");
RoomLocatCol.headerText="Locat";
RoomLocatCol.width=30;
var RoomoffCol:DataGridColumn=new DataGridColumn("Office");
RoomoffCol.headerText="Office";
RoomoffCol.width=30;
var RoomRemarkCol:DataGridColumn=new DataGridColumn("Remark");
RoomRemarkCol.headerText="Remark";
RoomRemarkCol.width=30;
var RoomCbCol:DataGridColumn=new DataGridColumn("CreatedBy");
RoomCbCol.headerText="CreatedBy";
RoomCbCol.width=30;
var RoomDCCol:DataGridColumn=new DataGridColumn("DateCreated");
RoomDCCol.headerText="DateCreated";
RoomDCCol.width=30;
var myDP:DataProvider=new DataProvider(teamXML);
aDg.columns=[RoomIDCol,RoomNameCol,RoomDecCol,RoomLocatCol,RoomoffCol,RoomRemarkCol,RoomCbCol,RoomDCCol];
aDg.width=700;
aDg.dataProvider=myDP;
aDg.rowCount=aDg.length;
}
function openHandler(event:Event):void {
trace("openHandler: " + event);
}
function progressHandler(event:ProgressEvent):void {
trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}
function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}
function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
运行后得出效果如下:
<%@ Page language="c#" CodeFile="test.aspx.cs" AutoEventWireup="false" Inherits="test" %>
test.aspx.cs 内容:
public partial class test : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处定义dataset 并且访问数据库。
DataSet ds = new DataSet();
ds = //访问数据库的function();
// 在此处把dataset转换成xml发送回去。
Response.Write( ds.GetXml());
}
}
Flash 端:
新建ActionScript 3.0 的Flash。
windows--->components-->DataGird 托拽到界面中。 命名为:aDg
在第一帧action中
写下以下代码
import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;
import flash.net.*;
import flash.display.*;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.sendToURL;
import flash.external.ExternalInterface;
import flash.xml.XMLDocument;
import flash.xml.XMLNode;
import flash.xml.XMLNodeType;
var loader:URLLoader = new URLLoader();
var URLpreFix:String="http://itd-cecilia/website/test.aspx"; //http://itd-cecilia/website/test.aspx为服务器地址
getresult1();
function getresult1(){
var url:String=URLpreFix;
var request:URLRequest=new URLRequest(url);
trace("sendToURL);
var loader:URLLoader = new URLLoader();
loader.dataFormat=URLLoaderDataFormat.TEXT;
configureListeners(loader);
loader.load(request);
stop();
}
function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
function completeHandler(event:Event):void {
var loader:URLLoader=URLLoader(event.target);
trace("completeHandler: " + loader.data);
var teamXML:XML = new XML(loader.data);
var RoomIDCol:DataGridColumn=new DataGridColumn("RoomID");
RoomIDCol.headerText="ID";
RoomIDCol.width=20;
var RoomNameCol:DataGridColumn=new DataGridColumn("RoomName");
RoomNameCol.headerText="Name";
RoomNameCol.width=30;
var RoomDecCol:DataGridColumn=new DataGridColumn("RoomDescription");
RoomDecCol.headerText="Dec";
RoomDecCol.width=30;
var RoomLocatCol:DataGridColumn=new DataGridColumn("RoomLocation");
RoomLocatCol.headerText="Locat";
RoomLocatCol.width=30;
var RoomoffCol:DataGridColumn=new DataGridColumn("Office");
RoomoffCol.headerText="Office";
RoomoffCol.width=30;
var RoomRemarkCol:DataGridColumn=new DataGridColumn("Remark");
RoomRemarkCol.headerText="Remark";
RoomRemarkCol.width=30;
var RoomCbCol:DataGridColumn=new DataGridColumn("CreatedBy");
RoomCbCol.headerText="CreatedBy";
RoomCbCol.width=30;
var RoomDCCol:DataGridColumn=new DataGridColumn("DateCreated");
RoomDCCol.headerText="DateCreated";
RoomDCCol.width=30;
var myDP:DataProvider=new DataProvider(teamXML);
aDg.columns=[RoomIDCol,RoomNameCol,RoomDecCol,RoomLocatCol,RoomoffCol,RoomRemarkCol,RoomCbCol,RoomDCCol];
aDg.width=700;
aDg.dataProvider=myDP;
aDg.rowCount=aDg.length;
}
function openHandler(event:Event):void {
trace("openHandler: " + event);
}
function progressHandler(event:ProgressEvent):void {
trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}
function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
function httpStatusHandler(event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
}
function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
运行后得出效果如下: