Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

Send variables from flash to php

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

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.