Return to Snippet

Revision: 22802
at January 22, 2010 14:32 by allnatural


Initial Code
// Create JSON Object to send to PHP
import flash.net.URLRequest;
import flash.net.URLLoader;
import com.serialization.json.JSON;

//var obj:Object = JSON.deserialize(string); // Use this to deserialize data coming back!


var people:Array = new Array();
var person:Object = new Object();
person.firstname = "Kobe";
person.lastname = "Bryant";
people.push(person);

var url:String = "http://localhost/getJSON.php";
var request:URLRequest = new URLRequest(url);
request.method = URLRequestMethod.POST;

var requestVars:URLVariables = new URLVariables();
requestVars.myObject = JSON.serialize(people);
request.data = requestVars;

var loader:URLLoader = new URLLoader();
loader.load(request);

/* PHP TO CATCH THE JSON

$object = JSON_decode($_POST['myObject']);

// Takes JSON data and writes to data.txt
$fp = fopen('data.txt', 'w');
fwrite($fp, $_POST['abc']);
fwrite($fp, $object[0]->firstname . " ");
fwrite($fp, $object[0]->lastname . chr(13) . chr(10));
fwrite($fp, $_POST['myObject']);
fclose($fp);


*/

Initial URL
http://www.destroyyourcomputer.com

Initial Description
Uses JSON Lite SWC/Class from http://thanksmister.com/?p=40

Initial Title
Flash -> JSON -> PHP

Initial Tags
php, json

Initial Language
ActionScript 3