Skip to content

Instantly share code, notes, and snippets.

@laktek
Created February 13, 2010 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laktek/303159 to your computer and use it in GitHub Desktop.
Save laktek/303159 to your computer and use it in GitHub Desktop.
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import com.adobe.serialization.json.JSON; //download from http://code.google.com/p/as3corelib/
function initateGame(playerId):void
{
var dataToSave = [playerId];
// Point the request to the script that will handle the JSON
var request:URLRequest = new URLRequest( "http://localhost:8000" );
// Set the data property to the dataToSave XML instance to send the XML
// data to the server
request.data = JSON.encode(dataToSave);
//request.data = variables;
// Set the contentType to signal JSON data being sent
request.contentType = "application/json";
// Use the post method to send the data
request.method = URLRequestMethod.POST;
// Create a URLLoader to handle sending and loading of the JSON data
var loader:URLLoader = new URLLoader( );
// When the server response is finished downloading, invoke handleResponse
loader.addEventListener( Event.COMPLETE, handleResponse );
// Finally, send off the XML data to the URL
loader.load( request );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment