Flash CS3 and PHP - Send and Receive data
Codes
sendtophp.as
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
public class sendtophp extends Sprite {
var phpFile:String = "sendDataToServer.php";
public function sendtophp():void {
callBtn.addEventListener(MouseEvent.CLICK, callServer);
}
function callServer(e:MouseEvent):void {
var urlRequest:URLRequest = new URLRequest(phpFile);
var urlParams:URLVariables = new URLVariables();
urlParams.sampleVal = sendTxt.text;
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = urlParams;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, serverResponse);
loader.load(urlRequest);
}
function serverResponse(e:Event):void {
var loader:URLLoader = URLLoader(e.target);
var variables:URLVariables = new URLVariables(loader.data);
responseTxt.text = variables.returnValue;
}
}//end of class sendtophp
}//end of package
sendDataToServer.php
< ? php
print "returnValue= Hi ".$_POST['sampleVal'].", it's working";
?>
Source File - Sending2Server.zip
Comments
However, you dint see what I mentioned "utf-8" characters - To be specific, some asian language fonts.
But I solved the problem by using ARIAL UNICODE MS font. (you could see what I have done in here
Thanks once again for taking time to reply me.
Try this code
Flash
-----
navigateToURL( new URLRequest("sendDataToServer.php?sampleVal="+inputText.text),"_self");
here inputText.text is the text you have to send.
php
===
print "data from flash =".$_GET['sampleVal'];