Gruzin Posted October 4, 2006 Share Posted October 4, 2006 Hi guys,How can I send variables from flash to php? Yes I have tried Google :) , but no had no luck...Here is the Actionscript I'am using:[code]submit.onPress = function () { getURL ("flash.php", "_blank", "POST"); }[/code]but the flash.php file doesn't load..Hope someone can help with this and I assume this is the right forum :-\Thanks,George Quote Link to comment Share on other sites More sharing options...
yonta Posted October 4, 2006 Share Posted October 4, 2006 Here's how you could do it:[code]var objSend:LoadVars = new LoadVars(); /*Values (id) to be sent to php*/ objSend.id = promoid; /*Sending variables to php and loading returned variables (post method)*/ objSend.sendAndLoad("promocoes.php"+"?nocache=" + Math.random(), objManda, "POST"); /*When the results are received*/ objSend.onLoad = function(ok) { if (ok) { /*you now access the variables inside the php as this.variablename*/ _root.movieclipname.text = this.mytitle; _root.movieclipname.text = this.mymessage; } };[/code]This actionscript expects php to process $_POST['promoid'] and print something like &mytitle=tittle 1&mymessage=text1 whateverYou could also print xml from php and use something likevar nXML = new XML();nXML.ignoreWhite = true;nXML.onLoad = function(){ } gXML.sendAndLoad(file, nXML);For more info search for the Kirupa forums, LoadVars.send (eg. http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary434.html) or sendAndLoad, Xml.send (http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary855.html ). Just some clues.Best :) Quote Link to comment Share on other sites More sharing options...
Gruzin Posted October 4, 2006 Author Share Posted October 4, 2006 Thank you very much, but what should I add on submit button?I've tryed something like this, but when I click on submit button it doesn't open a php file called flash.php...Actually, I just want the text inputed in flash textbox to be sent as a variable for php.Thanks again for your time ;) [code]var objSend:LoadVars = new LoadVars(); /*Values (id) to be sent to php*/ objSend.id = promoid; sub.onRelease = gio; function gio(){ objSend.sendAndLoad("flash.php"+"?nocache=" + Math.random(), objManda, "POST"); } /*When the results are received*/ objSend.onLoad = function(ok) { if (ok) { /*you now access the variables inside the php as this.variablename*/ _root.movieclipname.text = this.user; _root.movieclipname.text = this.pass; } };[/code] Quote Link to comment Share on other sites More sharing options...
yonta Posted October 4, 2006 Share Posted October 4, 2006 How about this:[code]_root.sub.onRelease = function () { loadphpVariables();}function loadphpVariables(){ var objSend:LoadVars = new LoadVars(); /*Values (id) to be sent to php from textbox text value */ objSend.id = _root.textboxname.text; /*Sending variables to php and loading returned variables (post method) -> there was a typo here objSend not ObjManda*/ objSend.sendAndLoad("flash.php"+"?nocache=" + Math.random(), objSend, "POST"); /*When the results are received*/ objSend.onLoad = function(ok) { if (ok) { /*you now access the variables inside the php as this.variablename*/ _root.movieclipname.text = this.mytitle; _root.movieclipname.text = this.mymessage; } };}[/code]I haven't tested it but this how i remember it should be. Look for some tutorials here http://www.kirupa.com/web/index.htmHope it helps Quote Link to comment Share on other sites More sharing options...
Gruzin Posted October 5, 2006 Author Share Posted October 5, 2006 yonta, thank you very much for your help ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.