After a lot of research and some help from my friend Mark, I finally put together a small demo of posting data from a client side flash file to a server. In this example the flash file simply sends the text “Hello” to the server, and the sever reads this and saves it to a text file. Simple stuff but unusually hard to figure out, with a serious shortage of helpful information online.
- Your user plays a flash game you made, and you want to submit their high score back to the server to store in a databse
- Your flash file uses a form to collect data from the user which needs storing in a database
var store:LoadVars = new LoadVars(); //Make a new variable storage collectionstore[“testField”]=”Hello”; //Create an entry in the variable collection named “testField”
store.sendAndLoad(“http://localhost:51527/testForm/Default.aspx”,store,”POST”); //Send variables to ASP.NET
NB: – The sendAndLoad method posts the data silently without opening a browser window,hence the aspx page is never rendered to the user.
NB:- The second argument of sendAndLoad can be any LoadVars object used to retrieve a response from server if one is present (not rnecessary for one way data posting so here I used the original LoadVars object) .
ASP.NET (Server Side)
string field = Request.Params.Get(“testField”).ToString(); // get the parameter StreamWriter me = new StreamWriter(“C:/dump.txt”,false);
me.Write(field); //Write the parameter to a file