How to pass parameters from php to flash?
Moderator: General Moderators
How to pass parameters from php to flash?
sorry, if I am wrong forum.I know in php to pass parameters, use:
<name>. php? variable = <value>
And $ _REQUEST to get.
I was able to transfer from flash to php.I'm having trouble both transmission and reception.How to transfer values from php to flash?Flash supports the same function with the function '$ _REQUEST'?
thank
<name>. php? variable = <value>
And $ _REQUEST to get.
I was able to transfer from flash to php.I'm having trouble both transmission and reception.How to transfer values from php to flash?Flash supports the same function with the function '$ _REQUEST'?
thank
Re: How to pass parameters from php to flash?
flash to php:
yoursite.com/page.php?var1=value1&var2=value2
php to flash:
echo("var1=".$value1."&var2=".$value2);
make sure you're saving the variables to an MC in your frame so you can use them
The variable names in your MC are the same as the ones echoed in PHP
yoursite.com/page.php?var1=value1&var2=value2
php to flash:
echo("var1=".$value1."&var2=".$value2);
make sure you're saving the variables to an MC in your frame so you can use them
The variable names in your MC are the same as the ones echoed in PHP
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: How to pass parameters from php to flash?
Look into using fscommand (google: "flash fscommand"). This will allow your flash object to interact with a jscript on your page. Once you connect those dots, you can use PHP to output data within a dynamically generated jscript, or you can use jscript to make AJAX calls and fetch data from PHP asynchronously.Huynh wrote:sorry, if I am wrong forum.I know in php to pass parameters, use:
<name>. php? variable = <value>
And $ _REQUEST to get.
I was able to transfer from flash to php.I'm having trouble both transmission and reception.How to transfer values from php to flash?Flash supports the same function with the function '$ _REQUEST'?
thank
Re: How to pass parameters from php to flash?
I can show you what exactly I used for mine, but flash takes forever to open on my computer, so i'll post a link instead.
http://www.kirupa.com/developer/actions ... _mysql.htm
http://www.kirupa.com/developer/actions ... _mysql.htm
Re: How to pass parameters from php to flash?
thank the good idea.
I found:
in flash:
Everything is fine except mc_rect not disappear with alpha = 2.
I found:
Code: Select all
$nome="";
$x="10";
$alpha="2";
$vars .= "" ;
......
$row=mysql_fetch_row($result);
$vars .= "nome=" . $nome . "&" ;
$vars .= "x=" . $row[1] . "&" ;
$vars .="alpha=".$alpha."&";
echo $varsCode: Select all
myVars = new LoadVars ();
// call the load method to load my php page
myVars.load( "http://localhost/read1.php" );
//trace(myVars.nome)
//trace(myVars.x)
//trace(myVars.alpha) // "pietro@flash-php.it"
myVars._path = this
myVars.onLoad = function(success){
if (success){
//trace (" variables loaded ");
tposx.text=myVars.x;
tposy.text=myVars.y; // "pietro"
mc_rect._alpha=int(myVars.alpha);
} else {
trace (" Error loading variables ");
}
Re: How to pass parameters from php to flash?
try loadVariables instead.
And use _root.mc_rect
And use _root.mc_rect
Re: How to pass parameters from php to flash?
Your idea is great.I appreciate it.
I have a movieclip named mc_soldiers and I have tried:
With alpha and x in php is 2 and 10 (second and third columns of the database).Put all the code on the event onRelease of a button.It worked.Mc_soldiers become transparent.Movieclip has moved.
I added two columns in mysql.
Our name is 'account, pass'.
Each account will have x, y and alpha in its own
add into read1.php:
my actionscript:[/color][/b]
success.But the variable x, alpha received was undefined.
what happened?
I want to get the alpha value after logging
I have a movieclip named mc_soldiers and I have tried:
Code: Select all
mc_soldiers.loadVariables ('localhost/read1.php','');
_root.mc_soldiers._x = parseInt (myVars.x);
_root.mc_soldiers._alpha = parseInt (myVars.alpha);
I added two columns in mysql.
Our name is 'account, pass'.
Each account will have x, y and alpha in its own
add into read1.php:
Code: Select all
$name=$_POST["uname"];
$pass=$_POST["passw"];
....
$query = mysql_query ( "SELECT * FROM $table WHERE account = '".$name."' and pass='".$pass."'");
$num = mysql_num_rows ( $query );
if( $num > 0 )
{
$row=mysql_fetch_row($query);
$vars="";
$vars.="alpha=".$row[5]."&";//I checked column
....
echo $vars;
[b][color=#804080]}Code: Select all
submit.onRelease = function(){
//call php to verify the correct username and password
var myVars: LoadVars = new LoadVars();
myVars.uname = tuser.text;
myVars.passw = tpass.text;
myVars. onLoad = function(success){
if ( success ) {
msgbox.text = "ok" ;
} else {
msgbox.text = "not ok" ;
}
};
myVars.sendAndLoad ( "read1.php" , myVars, 'POST' ) ;
};what happened?
I want to get the alpha value after logging
Re: How to pass parameters from php to flash?
mc_soldiers.loadVariables ('localhost/read1.php','');
should be
_root.mc_soldiers.loadVariables ('localhost/read1.php', 'GET');
never assume in flash
if it's returning undefined, open the php page with your browser and check for errors in the PHP code. I guarantee that's what it is.
Oh, and GET is slightly faster than POST, but POST can send more data (my understanding)
should be
_root.mc_soldiers.loadVariables ('localhost/read1.php', 'GET');
never assume in flash
Code: Select all
$result = mysql_query ( "SELECT * FROM `".$table."` WHERE `account` = '".$name."' AND `pass`='".$pass."'");
if(!$result){
echo(mysql_error());
exit();
}
if(mysql_num_rows($result) == 0){
echo("no results returned");
exit();
}
$row = mysql_fetch_array($result);
echo("alpha=".$row["alpha"]);
Oh, and GET is slightly faster than POST, but POST can send more data (my understanding)
Re: How to pass parameters from php to flash?
I get this error when running the php:
Notice: Undefined index: uname in C:\xampp\htdocs\read1.php on line 14
Notice: Undefined index: passw in C:\xampp\htdocs\read1.php on line 15
no results returned.
read1.php:
I think uname and passw is in the flash 
Notice: Undefined index: uname in C:\xampp\htdocs\read1.php on line 14
Notice: Undefined index: passw in C:\xampp\htdocs\read1.php on line 15
no results returned.
read1.php:
Code: Select all
14.$name=$_POST["uname"];
15.$pass=$_POST["passw"];
Re: How to pass parameters from php to flash?
Code: Select all
if(isset($_POST["uname"])){
$name = $_POST["uname"];
}
if(isset($_POST["passw"])){
$pass = $_POST["passw"];
}
echo("Username: ".$name);
echo("Password: ".$pass);
Re: How to pass parameters from php to flash?
I tried your code.It informs $name and $pass is empty.
when I, I get the onLoad=%5Btype%20Function%5D&passw=123&uname=John.
sendAndLoad replaced by
Your code worked.But it opens up a php page in the browser.php I want to hide when it action.
But after four hours long, I've found a solution.Instead of using '$ _POST' I use $ _REQUEST.The database connection as usual.
php:
I added a global variable php_process: new LoadVar
actionscript:
php_process will contain all the information from php
the movieclip:
Ctrl + Enter.
I get nothing.Open server directory path.Run Login.swf in it-> message: localhost local internet connection.I run localhost / xampp with IE.
Ctrl + Enter again.Its work.Transmit and receive effective.
Only one thing is to run 'login.swf' localhost folder, it appears to try to connect 'allow-internet' localhost.
So, I have trouble when I send 'login.php' and 'Login.swf' to the server.If a freehost, I note what?
when I
Code: Select all
trace (myVars)sendAndLoad replaced by
Code: Select all
'myVars.send ("http://localhost/read11.php", "_blank", "POST");'But after four hours long, I've found a solution.Instead of using '$ _POST' I use $ _REQUEST.The database connection as usual.
php:
Code: Select all
if ($ num> 0)
{
$ row = mysql_fetch_row ($ query);
echo ("&result_ =". $row [2 ]);// 2 is the column containing alpha
$ alpha = $row [2];
$ vars = "";
$ vars .= "Nome = &";
$ vars .= "alpha =". $ alpha ."&";
echo $ vars;
}
actionscript:
Code: Select all
submit.onRelease = function () {
var myVars: LoadVars = new LoadVars ();
myVars.uname = tuser.text;
myVars.passw = tpass.text;
myVars.sendAndLoad ("http://localhost/read11.php" php_process, "POST");
};
php_process.onLoad = function (success) {
if (success) {
msgbox.text = php_process.result_;
Else {}
msgbox.text = "not send";
}
};
the movieclip:
Code: Select all
_root.troop._alpha = php_process.alpha;I get nothing.Open server directory path.Run Login.swf in it-> message: localhost local internet connection.I run localhost / xampp with IE.
Ctrl + Enter again.Its work.Transmit and receive effective.
Only one thing is to run 'login.swf' localhost folder, it appears to try to connect 'allow-internet' localhost.
So, I have trouble when I send 'login.php' and 'Login.swf' to the server.If a freehost, I note what?
Last edited by Huynh on Sun Oct 30, 2011 4:34 am, edited 1 time in total.
Re: How to pass parameters from php to flash?
again, I would suggest LoadVariables
'myVars.send ("http://localhost/read11.php", "_blank", "POST"); is opening your PHP script in a blank(_blank) window.
LoadVariables uses URL injection, so your $_POSTs won't work
'myVars.send ("http://localhost/read11.php", "_blank", "POST"); is opening your PHP script in a blank(_blank) window.
LoadVariables uses URL injection, so your $_POSTs won't work
Re: How to pass parameters from php to flash?
I'm nearly.Login only to flash a record.Simple.If I replace
with
For example enter search terms in flash, php will find and send to flash.It will be sent to the flash array.How do I send an array in php to flash?What to do to receive and display the array from php in 'flash'?
Code: Select all
$ row = myssql_fetch_row ($ res) Code: Select all
while ($ row = myssql_fetch_array ($ res)){
//What is there to send to flash?
}
For example enter search terms in flash, php will find and send to flash.It will be sent to the flash array.How do I send an array in php to flash?What to do to receive and display the array from php in 'flash'?
Re: How to pass parameters from php to flash?
Code: Select all
echo("returned=true");
$i=0;
while ($ row = myssql_fetch_array ($ res)){
$i++;
echo("&variable".$i."=".$row["column"]);
}
echo("&last=".$i);
for(i=0;i<=this.last;i++){
_root.msgbox.text += "\n"+this["variable"+i];
}
Re: How to pass parameters from php to flash?
Also use '& variable =' to send an array to flash.Sent from php is nice.But there is something in this ["variable" + i]It is undefined.When I replacethis ["variable" + i] by receive.variable1, it ok.An array is arrayVar [num] in flash.
I do not understand: what is this ["variable" + i]?
I'm thinking 'receive.variable + i'-> receive.variable1, receive.variable <n>
H ow?
I do not understand: what is this ["variable" + i]?
I'm thinking 'receive.variable + i'-> receive.variable1, receive.variable <n>
H ow?