Jump to content


Photo

Send variables from flash to php


  • Please log in to reply
4 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 04 October 2006 - 10:03 AM

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:

submit.onPress = function () { 
      getURL ("flash.php", "_blank", "POST"); 
}

but the flash.php file doesn't load..
Hope someone can help with this and I assume this is the right forum  :-\

Thanks,
George

I don't need your script, I'll try to write it myself

#2 yonta

yonta
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 04 October 2006 - 12:08 PM

Here's how you could do it:

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;
			
		}
		
	};

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...tionary434.html) or sendAndLoad, Xml.send (http://www.adobe.com...tionary855.html ). Just some clues.

Best :)
do it, do it right, do it right now

#3 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 04 October 2006 - 01:04 PM

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  ;)

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;
			
		}
		
	};

I don't need your script, I'll try to write it myself

#4 yonta

yonta
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 04 October 2006 - 07:31 PM

How about this:

_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;
			
		}
		
	};
}

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
do it, do it right, do it right now

#5 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 05 October 2006 - 08:14 PM

yonta, thank you very much for your help  ;)
I don't need your script, I'll try to write it myself




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users