Posted under » Flash on 13 March 2009
One of my favourite uses of flash. These 3 methods could assist you in sending variables and hence interact with server side languages like PHP and ASP.
All three methods have different syntax and will not work if you just change the tag send to tag sendAndLoad.
send
submit_button.onRelease = function(){ submitURL = "login.php"; // create a LoadVars object instance and populate it. send_lv = new LoadVars(); send_lv.username = "Robert"; send_lv.password = "DeNiro"; //now the magic send_lv.send(submitURL, "_self", "POST"); };
Load
submit_button.onRelease = function(){ // Load what? var result_lv:LoadVars = new LoadVars(); result_lv.onLoad = function(success:Boolean) { if (success) { result_ta.text = "We are in business."; } else { result_ta.text = "Error connecting to server."; } }; //now the magic my_lv.load("http://www.helpexamples.com/flash/params.txt"); };
Another method to load variables is by using flashvars.
sendAndLoad
submit_button.onRelease = function(){ submitURL = "login.php"; // Load what? var result_lv:LoadVars = new LoadVars(); result_lv.onLoad = function(success:Boolean) { if (success) { result_ta.text = "We are in business."; } else { result_ta.text = "Error connecting to server."; } }; // send what? send_lv = new LoadVars(); send_lv.username = "Robert"; send_lv.password = "DeNiro"; //now the magic send_lv.sendAndLoad(submitURL, result_lv, "POST"); };