Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flash and PHP - send vars then retreive 3

Status
Not open for further replies.

martinb7

Programmer
Joined
Jan 5, 2003
Messages
235
Location
GB
Hi, i was wondering how you would send some vars to a php page from flash, the php does something, then flash retrevies the answer??

like a calculator for instance.

i dont know where to go!!

::php code::

<?php
//calc test
$n1 = $HTTP_POST_VARS[num1];
$n2 = $HTTP_POST_VARS[num2];

$res = $n1 + n2;

echo &quot;&res=&quot;.$res;
?>

flash .fla

im stuck

PS, whats the difference between print & echo?

and whats printf and the like do??




Thanx

Martin

Computing help and info:

 
If you use the sendAndLoad() method of the loadVars object you'll get what you need:

Code:
sendInfo = new LoadVars();//object to send data
receiveInfo = new LoadVars();//object to receive returned data
receiveInfo.onLoad=function(){//function to work with returned data
	trace(this.res);//show answer
	}
sendInfo.num1 = 10;//set up values to send out sendInfo.num2 = 12;//(can be done with variables but hard coded here)

sendInfo.sendAndLoad('php/doStuff.php', receiveInfo, &quot;POST&quot;);//send to script

...as far as Flash is concerned print and echo are the same thing: print is a function and returns a value within PHP while echo doesn't, it merely outputs a value - echo is slightly faster than print.

printf is used to format output, according to rules you build into the statement:

printf ( string format [, mixed args])
 
Missed a line break above after a comment, here's the code alone:

Code:
sendInfo = new LoadVars();
receiveInfo = new LoadVars();
receiveInfo.onLoad=function(){
	trace(this.result);
	}
sendInfo.value1 = 10;
sendInfo.value2 = 12;
sendInfo.sendAndLoad('php/doStuff.php', receiveInfo, &quot;POST&quot;);
 
Just found this post. THANK YOU SO MUCH WANGMAN!

thx thx thx
 
I'm learning flash and I have a project i'm developing whereby the end-user will need to refresh data from time to time to be displayed within a Flash site. They will be posting updatable press releases sourced from some kinda database. I was advised by a different expert xml is the way to go. I have no idea how to code or enact xml to nest into a flash page. Can Flash handle this alone w/o programming in another language? If so, what's the ActionScript to enable this? Thanks is advance!
 
XML is suported by flash as i'm aware from v.5.0
Code:
this was tested with MX 2004
[code]
the text.xml file had only this line
<XML prop1=&quot;test&quot; prop2=&quot;100&quot;/>
you can send all the data you need from the server as the properties to 1 XML record and use it's firstChild to access them

var x=new XML()
x.onLoad = function (success)
{
	trace(&quot;loaded &quot;+success)
	for(i in this.firstChild.attributes) trace(this.firstChild.attributes[i])
        //or access the attributes directly
        trace(this.firstChild.attributes[&quot;prop1&quot;])
        trace(this.firstChild.attributes[&quot;prop2&quot;])
        //etc
}
x.load(&quot;test.xml&quot;);

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top