Flash cs3,Flex与asp通信
flash与asp:
先把两个代码贴一下:
flash:
var loader:URLLoader = new URLLoader();
var url:URLRequest = new URLRequest("test.asp");
url.method = URLRequestMethod.POST;
var values:URLVariables = new URLVariables();
values.message="hello im flash!";
url.data = values;
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE,loaded);
function loaded(e:Event) {
out1.text=loader.data;
//outPut: phpMessage=im php message!&flashMessage=hello im flash!
out2.text=loader.data.phpMessage;
// im php message!
out3.text=loader.data.flashMessage;
// hello im flash!
out4.text=loader.data.dbMessage;
}
loader.load(url);
asp:
<%@LANGUAGE="JAVASCRIPT"%>
<%
//接收flash传进来的数据
var flashData;
flashData = Request("message");
//发给flash的数据
var aspMessage;
aspMessage = ’im asp message!’;
//数据库的相关操作
//======================================
var conn;
var rs;
var sql;
var strPath;
strPath="test.mdb";
try{
conn = Server.CreateObject("ADODB.Connection");
conn.connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strPath);
conn.open();
}catch(e){
Response.Write(’<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><div style="font-size:12px;font-weight:bold;border:1px solid #006;padding:6px;background:#fcc">数据库连接出错,请检查连接字串!</div>’);
Response.End
}
rs=Server.createobject("ADODB.Recordset") ;
sql="select * from name" ;
rs.open(sql,conn,1,1);
//======================================
Response.Write("phpMessage="+aspMessage+"&"+"flashMessage="+flashData+"&"+"dbMessage="+rs("companyname"));
%>
看到flash和asp文件时面变量名就知道相互是怎么传送的呢,对于数据库的一些插入,更新,查询的操作,只要接收flash的数据,直接运行asp相关数据库操作命令就行了.直接复制到IIS的路径下即可测试.在线观看地址:
补充:flash教程,Action