Reputation:
I'm trying to do a PHP-Flash communication in ActionScript 3. I can send from Flash to PHP but I don't know how Flash can get a variable from PHP file.
Any help?
Upvotes: 1
Views: 744
Reputation: 536
Assuming your PHP code is on a server that has PHP enabled, you could do this :
Sample code (not tested, might be incorrect AS3 because this is Haxe) :
var l : URLLoader = new URLLoader();
var rq : URLRequest = new URLRequest("http://www.example.com/superdata.php");
l.dataFormat = URLLoaderDataFormat.TEXT;
l.addEventListener(Event.COMPLETE, success, false, 0, false);
l.load(rq);
function success (e : Event) : Void {
trace(e.target.data);
}
And on the PHP side of things :
<? echo "my data"; ?>
Upvotes: 3
Reputation: 4340
You should use AMFPHP and create a webservice. This way you can have SharedObjects and pass variables back and forth.
Upvotes: 1