Flash cs3、Flex与asp、php通信总结(包含数据库)

网站建设 2021-07-03 14:34www.dzhlxh.cn网站建设
flash与asp:
先把两个代码贴一下:
flash:

varloader:URLLoader=newURLLoader();

varurl:URLRequest=newURLRequest("test.asp");

url.method=URLRequestMethod.POST;

varvalues:URLVariables=newURLVariables();

values.message="helloimflash!";
url.data=values;

loader.dataFormat=URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE,loaded);
functionloaded(e:Event){
out1.text=loader.data;
//outPut:phpMessage=imphpmessage!&flashMessage=helloimflash!
out2.text=loader.data.phpMessage;
//imphpmessage!
out3.text=loader.data.flashMessage;
//helloimflash!
out4.text=loader.data.dbMessage;
}
loader.load(url);

asp:

<%@LANGUAGE="JAVASCRIPT"%>
<%
//接收flash传进来的数据
varflashData;

flashData=Request("message");
//发给flash的数据
varaspMessage;
aspMessage=’imaspmessage!’;


//数据库的相关操作
//======================================
varconn;
varrs;
varsql;
varstrPath;
strPath="test.mdb";
try{
conn=Server.CreateObject("ADODB.Connection");
conn.connectionString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" Server.MapPath(strPath);
conn.open();
}catch(e){
Response.Write(’<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/><pstyle="font-size:12px;font-weight:bold;border:1pxsolid#006;padding:6px;background:#fcc">数据库连接出错,请检查连接字串!</p>’);
Response.End
}
rs=Server.createobject("ADODB.Recordset");
sql="select*fromname";
rs.open(sql,conn,1,1);
//======================================
Response.Write("phpMessage=" aspMessage "&" "flashMessage=" flashData "&" "dbMessage=" rs("companyname"));

%>

看到flash和asp文件时面变量名就知道相互是怎么传送的呢,对于数据库的一些插入,更新,查询的操作,只要接收flash的数据,直接运行asp相关数据库操作命令就行了.直接复制到IIS的路径下即可测试.在线观看地址:http://www.wolf2999.cn/php/test.swf

flash与php:
先把两个代码贴一下:
flash:

varloader:URLLoader=newURLLoader();

varurl:URLRequest=newURLRequest("test.php");

url.method=URLRequestMethod.POST;

varvalues:URLVariables=newURLVariables();

values.message="helloimflash!";
url.data=values;

loader.dataFormat=URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE,loaded);
functionloaded(e:Event){
out1.text=loader.data;
//outPut:phpMessage=imphpmessage!&flashMessage=helloimflash!
out2.text=loader.data.phpMessage;
//imphpmessage!
out3.text=loader.data.flashMessage;
//helloimflash!
out4.text=loader.data.dbMessage;
}
loader.load(url);
php:

<?php
//这里都是有关数据库的操作
//===================================
Define(’DATABASE_SERVER’,’localhost’);
Define(’DATABASE_USERNAME’,’root’);
Define(’DATABASE_PASSWORD’,’root’);
Define(’DATABASE_NAME’,’flextest’);
$link=@mysql_connect(DATABASE_SERVER,DATABASE_USERNAME,DATABASE_PASSWORD);
@mysql_select_db(DATABASE_NAME,$link);
$result=@mysql_query("Select*fromusers");
$user=@mysql_fetch_array($result,MYSQL_ASSOC);
//echo$user[’userid’];
$dbvar=$user[’userid’];
//===================================
//接收flash传进来的数据
$flashData=$_POST[’message’];
//给flash发送的数据
$phpMessage=’imphpmessage!’;
echo"phpMessage=$phpMessage&flashMessage=$flashData&dbMessage=$dbvar";
?>
代码很简单,不用多解释,其实和asp的没有多大区别的.直接复制到php的路径下即可测试.数据库文件直接在phpMyAdmin狼蚁网站SEO优化执行flextest.sql里的sql语句就行了.因为公司禁端口,我不能在线操作我空间的sql的数据库,在线演示地址就没有,等有时间在家里加上.

Flex与php:
先把两个代码贴一下:
Flex:

<?xmlversion="1.0"encoding="utf-8"?>
<mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"creationComplete="onInit()"xmlns="*"layout="absolute"backgroundGradientColors="[#ffffff,#c0c0c0]">
<mx:Script>
<![CDATA[
publicfunctiononInit():void
{
userRequest.send();
}
]]>
</mx:Script>
<mx:HTTPServiceid="userRequest"url="request.php"useProxy="false"method="POST">
<mx:requestxmlns="">
<username>{username.text}</username><emailaddress>{emailaddress.text}</emailaddress>
</mx:request>
</mx:HTTPService>
<mx:Formx="22"y="10"width="356">
<mx:HBox>
<mx:Labeltext="Username"/>
<mx:TextInputid="username"/>
</mx:HBox>
<mx:HBox>
<mx:Labeltext="EmailAddress"/>
<mx:TextInputid="emailaddress"/>
</mx:HBox>
<mx:Buttonlabel="Submit"click="userRequest.send()"/>
</mx:Form>
<mx:DataGridid="dgUserRequest"x="22"y="128"dataProvider="{userRequest.lastResult.users.user}">
<mx:columns>
<mx:DataGridColumnheaderText="UserID"dataField="userid"/>
<mx:DataGridColumnheaderText="UserName"dataField="username"/>
</mx:columns>
</mx:DataGrid>
<mx:TextInputx="22"y="292"id="selectedemailaddress"text="{dgUserRequest.selectedItem.emailaddress}"/>
</mx:Application>
php:

<?php
/*ThankstoPeteMackieforthecodebelow*/

Define(’DATABASE_SERVER’,’localhost’);
Define(’DATABASE_USERNAME’,’root’);
Define(’DATABASE_PASSWORD’,’root’);
Define(’DATABASE_NAME’,’flextest’);

#Connecttothedatabase
$mysqli=newmysqli(DATABASE_SERVER,DATABASE_USERNAME,DATABASE_PASSWORD,DATABASE_NAME);

#Checkconnection
if(mysqli_connect_errno()){
printf("MySQLconnectfailed:%s\n",mysqli_connect_error());
exit();
}

#Quotevariabletomakesafe
functionquote_smart($value){
global$mysqli;
#Stripslashes
if(get_magic_quotes_gpc())
$value=stripslashes($value);

#Quoteifnotinteger
if(!is_numeric($value))
$value=$mysqli->real_escape_string($value);
return$value;
}

if(!empty($_POST)&&$_SERVER[’REQUEST_METHOD’]==’POST’){
if($_POST[’emailaddress’]&&$_POST[’username’]){
#Addtheuser
$query=sprintf("InsertINTOusersVALUES(’’,’%s’,’%s’)",quote_smart($_POST[’username’]),quote_smart($_POST[’emailaddress’]));
if(!@$mysqli->query($query)){
printf("’flextest’userdatabasequeryinserterror:%s\n",$mysqli->error);
$mysqli->close();
exit();
}
}
}

#Returnalistofalltheusers
if(!$result=@$mysqli->query("Select*fromusers")){
printf("’flextest’userdatabasequeryselecterror:%s\n",$mysqli->error);
$mysqli->close();
exit();
}

$xml_return="<users>";
while($user=mysqli_fetch_array($result,MYSQLI_ASSOC)){
$xml_return.=
"<user><userid>".$user[’userid’]."</userid><username>".$user[’username’]."</username><emailaddress>".$user[’emailaddress’]."</emailaddress></user>\n";
}
$xml_return.="</users>";
$mysqli->close();
echo$xml_return;
?>
这里的代码就是Adobe phpria sdk里的一个实例. 如果想要全部源码的请留下邮箱,我来发.flex与php的就不说了,直接把php的代码化成asp代码就行了,和flash的一道理了.

源码下载:https://www.jb51.net/files/soft/1_071030193505.rar

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板