Webjx核心提示:flash與asp: 先把兩個(gè)代碼貼一下: flash: varloader:URLLoader=newURLLoader(); varurl:URLRequest=newURLRequest(test.asp); url.method=URLRequestMethod.POST; varvalues:URLVariables=newURLVariables(); values.message=helloimflash!; url.data=values; loader.d |
flash與asp:
先把兩個(gè)代碼貼一下:
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傳進(jìn)來的數(shù)據(jù)
var flashData;
flashData = Request("message");
//發(fā)給flash的數(shù)據(jù)
var aspMessage;
aspMessage = ’im asp message!’;
//數(shù)據(jù)庫的相關(guān)操作
//======================================
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" /><p style="font-size:12px;font-weight:bold;border:1px solid #006;padding:6px;background:#fcc">數(shù)據(jù)庫連接出錯(cuò),,請檢查連接字串!</p>’);
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文件時(shí)面變量名就知道相互是怎么傳送的呢,對于數(shù)據(jù)庫的一些插入,更新,查詢的操作,只要接收flash的數(shù)據(jù),直接運(yùn)行asp相關(guān)數(shù)據(jù)庫操作命令就行了.直接復(fù)制到IIS的路徑下即可測試.在線觀看地址:http://www./php/test.swf
flash與php:先把兩個(gè)代碼貼一下:
flash:
var loader:URLLoader = new URLLoader();
var url:URLRequest = new URLRequest("test.php");
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);
php:
<?php
//這里都是有關(guān)數(shù)據(jù)庫的操作
//===================================
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 * from users");
$user=@mysql_fetch_array($result,MYSQL_ASSOC);
//echo $user[’userid’];
$dbvar=$user[’userid’];
//===================================
//接收flash傳進(jìn)來的數(shù)據(jù)
$flashData = $_POST[’message’];
//給flash發(fā)送的數(shù)據(jù)
$phpMessage = ’im php message!’;
echo "phpMessage=$phpMessage&flashMessage=$flashData&dbMessage=$dbvar";
?>
代碼很簡單,不用多解釋,其實(shí)和asp的沒有多大區(qū)別的.直接復(fù)制到php的路徑下即可測試.數(shù)據(jù)庫文件直接在phpMyAdmin下面執(zhí)行flextest.sql里的sql語句就行了.因?yàn)楣窘丝?我不能在線操作我空間的sql的數(shù)據(jù)庫,在線演示地址就沒有,等有時(shí)間在家里加上.
Flex與php:先把兩個(gè)代碼貼一下:
Flex:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onInit()" xmlns="*" layout="absolute" backgroundGradientColors="[#ffffff, #c0c0c0]">
<mx:Script>
<![CDATA[
public function onInit():void
{
userRequest.send();
}
]]>
</mx:Script>
<mx:HTTPService id="userRequest" url="request.php" useProxy="false" method="POST">
<mx:request xmlns="">
<username>{username.text}</username><emailaddress>{emailaddress.text}</emailaddress>
</mx:request>
</mx:HTTPService>
<mx:Form x="22" y="10" width="356">
<mx:HBox>
<mx:Label text="Username"/>
<mx:TextInput id="username"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Email Address"/>
<mx:TextInput id="emailaddress"/>
</mx:HBox>
<mx:Button label="Submit" click="userRequest.send()"/>
</mx:Form>
<mx:DataGrid id="dgUserRequest" x="22" y="128" dataProvider="{userRequest.lastResult.users.user}">
<mx:columns>
<mx:DataGridColumn headerText="User ID" dataField="userid"/>
<mx:DataGridColumn headerText="User Name" dataField="username"/>
</mx:columns>
</mx:DataGrid>
<mx:TextInput x="22" y="292" id="selectedemailaddress" text="{dgUserRequest.selectedItem.emailaddress}"/>
</mx:Application>
php:
<?php
/* Thanks to Pete Mackie for the code below */
Define(’DATABASE_SERVER’, ’localhost’);
Define(’DATABASE_USERNAME’, ’root’);
Define(’DATABASE_PASSWORD’, ’root’);
Define(’DATABASE_NAME’, ’flextest’);
# Connect to the database
$mysqli = new mysqli(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME);
# Check connection
if (mysqli_connect_errno()) {
printf("MySQL connect failed: %s\n", mysqli_connect_error());
exit();
}
# Quote variable to make safe
function quote_smart($value) {
global $mysqli;
# Stripslashes
if (get_magic_quotes_gpc())
$value = stripslashes($value);
# Quote if not integer
if (!is_numeric($value))
$value = $mysqli->real_escape_string($value);
return $value;
}
if (!empty($_POST) && $_SERVER[’REQUEST_METHOD’] == ’POST’) {
if ($_POST[’emailaddress’] && $_POST[’username’]) {
# Add the user
$query = sprintf("Insert INTO users VALUES (’’, ’%s’, ’%s’)", quote_smart($_POST[’username’]), quote_smart($_POST[’emailaddress’]));
if (!@$mysqli->query($query)) {
printf("’flextest’ user database query insert error: %s\n", $mysqli->error);
$mysqli->close();
exit();
}
}
}
# Return a list of all the users
if (!$result=@$mysqli->query("Select * from users")) {
printf("’flextest’ user database query select error: %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里的一個(gè)實(shí)例. 如果想要全部源碼的請留下郵箱,我來發(fā).flex與php的就不說了,直接把php的代碼化成asp代碼就行了,和flash的一道理了.