Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/22963-send-variables-from-flash-to-php/
Share on other sites

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 whatever

You could also print xml from php and use something like

var 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 :)
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]
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.htm

Hope it helps
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.