/ Published in: ActionScript 3
Uses JSON Lite SWC/Class from http://thanksmister.com/?p=40
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// 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); */
URL: http://www.destroyyourcomputer.com